Wednesday, July 20, 2011

Making user settings available in cron

When using the unix command-line utility "cron" to run scripts at regular times, one potential headache is that cron will run the jobs as root. So, for example, environment variables defined in your .bashrc file will not be available to the script. There are probably a countable infinity of possible solutions to this problem; a simple one that works for me is to manually run the .bashrc file before the actual script, by calling bash with the "-c" flag. The line in your crontab might look like this:

    0 8 * * 1-5 bash -c '. /home/falloon/.bashrc; /home/falloon/Scripts/my_cron_job.py'

No comments:

Post a Comment