How to run the shell or bash scripts from php?

I have a bash script that I want to be run from php using a passthru function.
if you don’t need any output you can use shell_exec or exec without
escapeshellcmd function

$command=’/bin/bash /copy_images.sh ‘;
$escaped_command = escapeshellcmd($command);
passthru($escaped_command, $output);
print_r($output);
$output is returning the exit code that the php interpreter gives to the shell:
0 – successful execution of the program, this means that the script doesn’t work as expected on php side, but does on the unix box;
1 – file not found, run as root or use sudo to access via php;
2 – script completed successfully
127 –file not found;

My copy_images.sh script is

 #!/bin/sh
####################################
#Copy images
####################################
echo  | sudo -S cp -av /var/www/
This entry was posted in Debian&Ubuntu, Technologies and tagged , . Bookmark the permalink.