I have a shell script like this (in /usr/local/bin/esm-script/import-master.php):
#! /bin/bash
echo "this is the file name $1."
script -c 'PGPASSWORD="pwd123" /usr/bin/psql --host localhost --port 5432 --username "postgres" --no-password --quiet "dbESM" < "$1"' /dev/null
Now I'm calling it through a PHP script like this:
$NewFile = "/var/www/...master-data.sql"; //full path
$strImport = '/usr/local/bin/esm-script/import-master.sh ' . $NewFile;
$strMsg = shell_exec($strImport);
echo "$strMsg<br />";
echo 'done!';
However, when I run the PHP code, this is the message I get on the browser:
this is the file name /var/www/ESM-Backend/uploads/master-data.sql. Script started, file is /dev/null Script done, file is /dev/null sh: 1: cannot open : No such file Script started, file is /dev/null
done!
I'm not a shell scripting person so I don't know if I'm missing something.
I've checked that the folder with the sql file has the correct permissions (775) and has data (insert statements).
So why does this not work? Any ideas and guidelines are really appreciated.
EDIT I hard-coded the file in the shell script file like this:
script -c 'PGPASSWORD="#UR!23" /usr/bin/psql --host localhost --port 5432 --username "postgres" --no-password --quiet "dbESM" < "/var/www/ESM-Backend/uploads/master-data.sql"' /dev/null
And it works. But I need it to run with the file passed through PHP.