2

I read about cron. I edited it by running crontab -e and I added this line:

* * * * * php /var/www/createFile.php

When I run ls /tmp/ I do not see any file create by my php script. Why does not it work ?

when I run php /var/www/createFile.php it works fine, however (the effect is the creation of a text file in /tmp/

I changed the command to:

/usr/bin/php /var/www/createFile.php > /tmp/createFile.log 2>&1

As Jos suggested me below. When I run cat /tmp/createFile.log I get this:

python can not open file 'createfile.py': [Errno 2] No such file or directory

I used the full path to createfile.py as Jos suggested me in createFile.php now I get this error:

sh: nmap not found
0sh: nmap not found
2

Make sure that scripts called by cron, as well as subsequent scripts called by them, use full paths to the files referenced. Scripts that run perfectly well when run by the owner, but fail when executed by cron, nearly always have such a reference error.

Also, in order to find out why cron jobs fail, look at the syslog; if the cron job needs to write output to sysout, it will try to mail it to the user if sysout has not been redirected. Same goes for syserr.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy