I have a few bash and perl scripts which has been asked to be made executable through a web based interface. Nothing fancy, just for easy access.
PHP seemed to be the quick and dirty solution for the purpose [through exec()]. So I turned off the safe mode in php.ini and tried
$output = array();
exec('/var/www/vhosts/default/htdocs/scripts/RUN.sh',$OUTPUT);
print_r($output);
var_dump($output);
Now whatever files are accessed in the RUN.sh script (accessed though a relative path) are not found. Is there any way of getting this to work without giving complete path to every single redirect (or any file for that matter) that is being accessed in the scripts?
After applying the accepted solution:
Say one line form the script:
time python idsplitter.py OUTPUT/TMP/tokens OUTPUT/token_splits
echo "done"
While the time-s output gets pushed to error_log file, “done” is never passed to the $OUTPUT array. The returned value in the third argument to exec(), when printed on page gives 0.
Update:
time command puts it out to stderr so if do `
t=`time some_command 2>&1`
then also nothing gets stored in t. So that makes sense. Thanks for the help everyone …
Change the current working directory as part of the script itself.
Your working directory, from the perspective of the
RUN.shscript, isn’t what you think it is. Therefore, relative paths in the script don’t point where intended.To fix it you need to force the current working directory to be the one that works with the relative paths. So, either:
cd [/absolute/path]in theRUN.shscript, to force it to be correct.