0

我目前使用我们用来移动数据的 shell 脚本,它使用以下语法运行:

./script.sh <env> <y|n> <file> <file> <file> <file> <file> <file> 

$1 sets a variable for production/test
$2 sets a variable whether we perform a tarball of the destination folder before copying
$3 - $# is a space delimited list of files to move (there has to be a minimum of one file, no maximum)

我需要将此脚本传递给其他用户,但不要相信他可以通过 shell 访问该框。

我想做的是创建一个包含三个字段的网页。字段一是环境的单选按钮,将作为 $1 传递。字段二是是/否的单选按钮,我想将其传递为 2 美元。字段 3 是一个多选框,我想从静态文本文件或(最好)通过在源目录上运行“ls”来填充它 - 这将是 $3+

这可能吗?我可以在服务器上运行 Apache,这样 PHP 甚至 CGI 都可以使用。

谢谢!

4

2 回答 2

0

对的,这是可能的。但是,它将作为 Web 服务器用户运行。

只需使用system()exec()调用您的 bash 脚本。

文档: http: //php.net/manual/en/function.system.php http://php.net/manual/en/function.exec.php

确保使用escapeshellarg() http://www.php.net/manual/en/function.escapeshellarg.php摆脱不需要的输入。也许也可以编写自己的黑名单。

例子:

$script_path = '/path/to/script.sh';
system( $script_path . ' ' . $argument );
于 2013-05-07T09:56:39.180 回答
0
<?php
  if (!empty($_POST)) { //more tests required here...
    exec('sh /path/to/shell ' . $_POST['var1'] . ' '  . $_POST['var2'] . ' '  . $_POST['var3']);
  }
?>

http://php.net/manual/en/function.exec.php

于 2013-05-07T09:57:36.827 回答