将变量传递给shell脚本的网页

I currently use a shell script we use to move data around, which is run with the following syntax:

./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)

I need to pass this script to a different user, but don't trust him with shell access to the box.

What I'd like to do is create a web page with three fields. Field one is a radio button of the environment, which will be passed as $1. Field two is a radio button of yes/no, which I'd like passed as $2. And Field 3 is a multiselect box, which I'd like to be populated from either a static text file, or (preferably) from running an "ls" over the source directory - this will be $3+

Is this possible? I can run Apache on the server so PHP or even CGI will be available.

thanks!

Yes it is possible. It will be run as the web servers user however.

Just use system() or exec() to call your bash script.

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

Make sure to use escapeshellarg() http://www.php.net/manual/en/function.escapeshellarg.php to get rid of unwanted input.. Perhaps write your own blacklist as well.

Example:

$script_path = '/path/to/script.sh';
system( $script_path . ' ' . $argument );
<?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