denn0n Posted January 27, 2014 Share Posted January 27, 2014 (edited) Hello everyone, I'm new to this forum, I have the next problem I hope someone can advise. I have a php script I need to run from cronjobs. This script contains some commands shell_exec, fairly simple and the output is directed to a file, from the webmin module cronjobs goes well but when running from cron, the commands shell_exec stops working the cronjob is * * * * * php /some/path/myscript.php to make it easy #!/usr/bin/php -q <?php $iptables=shell_exec('iptables -S '); $file_name="/some/path/out_test.txt"; $ar=fopen("$file_name","w"); fputs($ar,$iptables); fputs($ar,"nn"); fclose($ar); ?> from the terminal when I run $ php /some/path/myscript.php as root, the file /some/path/out_test.txt is filled with the output of the command $ iptables-S but when run from cron, the file is blank Edited January 28, 2014 by denn0n Link to comment Share on other sites More sharing options...
thescientist Posted January 28, 2014 Share Posted January 28, 2014 are you checking in an error log? it sounds like the user the cron is running under doesn't have privileges to run that script. where as from the command line, you are probably running as root. Link to comment Share on other sites More sharing options...
denn0n Posted January 29, 2014 Author Share Posted January 29, 2014 are you checking in an error log? it sounds like the user the cron is running under doesn't have privileges to run that script. where as from the command line, you are probably running as root. i do apreciate your help thescientist but it is solve , between you have right and other things, the paths to the commands have to be full and for some init process on ubuntu you should put sudo before and the error log it is a great ideai put this afther the comand on cron to get a new file log error 2>/var/log/crontab.err Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now