Using Cron to run a python program

Carsten Haese carsten at uniqsys.com
Wed Nov 23 20:45:50 EST 2005


On 23 Nov 2005 16:23:11 -0800, vagrantbrad wrote
> I'm using python 2.4 running on Fedora Core 4.  I have written a python
> program called ipscan.py that checks the external ip address of my
> cable internet connection, and on change, will update the dns records
> at my dns provider, zoneedit.  So basically, I've setup dynamic dns
> using python.  Once the ip compare and/or update is complete, I log the
> results to a text file called update.log.  When I run the program in 
> a bash shell with the command "python ipscan.py", the program runs fine
> and the results are appended to update.log.  When I run this program 
> as a cron job under the root user with the previously mentioned 
> command, the program runs without errors but does not append an 
> entry to the log.  The permissions on the update.log file should not 
> be an issue since I'm running the cron job as root, but I've given 
> root write permissions just to be safe.  What would cause the 
> logging to work at a command prompt but fail in cron?  I'm not 
> getting any errors in the cron logs or /var/spool/mail/root.

You're not giving us much detail about your script, so we can only guess. My
guess is that your python script is either not invoked at all or it dies
(raises an exception) before appending to the update.log.

You should keep in mind that cron jobs don't run in a normal login shell,
don't have the normal environment variables, and are not attached to a tty.
Any of those factors can conceivably cause a script to fail under cron when it
works fine from a shell.

HTH,

Carsten.



More information about the Python-list mailing list