Simulate the environment of Cron Jobs

Often you will find yourself in the situation that one of your cron jobs works perfectly if you execute it manually but fails as soon as is gets executed by cron. The root cause might be the different environment. To simulate the environment of a cron job add the following entry to your crontab using crontab -e:

This will create the file cronenv in your root directory and dump all available environment variables into it. Once the file was created remove the entry from your crontab and take a look at its contents:

This pretty much sums up the environment. To enter this environment use the following command:

Now you can execute your cron job command, see what happens and fix your error. Once you’re done simply type exit to leave the environment.

See this Stack Overflow answer for more information.

This entry was posted in Debian, Ubuntu. Bookmark the permalink.