There is a php script, here's a piece of code from it.

$uploaddir = "/tmp/"; $updatedir = "/home/andy/test/"; $update_script_path = "/home/andy/updater.sh"; $uploadfile = $uploaddir.basename($_FILES['arch']['name']); $uploadfile = str_replace(' ', '', $uploadfile); if ($_FILES['arch']['tmp_name'] != "" && copy($_FILES['arch']['tmp_name'], $uploadfile)) { $update_script_path = escapeshellarg($update_script_path); $uploadfile = escapeshellarg($uploadfile); $updatedir = escapeshellarg($updatedir); $commandline = $update_script_path." ".$uploadfile." ".$updatedir; //echo "<pre>" . ($res = system($commandline)) . "</pre>"; echo "<pre>" . ($res = shell_exec($commandline)) . "</pre>"; //echo "<pre>" . ($res = exec($commandline)) . "</pre>"; //echo "<pre>" . ($res = system("/bin/sh -c /home/andy/updater.sh")) . "</pre>"; } 

Do not be confused by the commented launch lines, I just tried various options. There is a simple bash script, the rights to execute it are installed.

 #!/bin/sh tar -xvf $1 -C $2 

Those. The php script takes the file from the user, forms a command line to run the bash script. The problem is that the bash script does not work, the script in bash both arguments are passed correctly, I checked it out of the bash script

 echo $1 echo $2 

The bash script should unpack the file that the user submitted via the form to the specified directory, but nothing happens. If I call my bash script "manually" from the console

 root@test-device:/home/andy # ./updater.sh /tmp/files.tar.gz /home/andy/test/ 

That all works fine, as I can see from the code of the php script was played with different options, but did not get success (((

  • Specify the full path to the tar in the script - rjhdby

1 answer 1

You probably have a problem with insufficient permissions for the user, from which you are running the http-server and which processes the request to the specified script.

Check and add permissions:

  • for the folder /home/andy/test - write
  • for the script file /home/andy/updater.sh - for execution
  • If I call my bash script "manually" from the console, everything works fine. - Ipatiev
  • @ Ipatiev, in response, I wrote about the rights for the user, from which the http-server is running. And the HARDWARE writes that everything works correctly, from the console under the user andy. - Jigius