beta.blog

Debugging crontab issues

by on Oct.15, 2024, under News

Assuming we declared the following crontab entry which is not working properly and we’d like to know why:

# everyday at 03:00am run db script
0 3 * * * /root/my_db_script.sh

We may now simply append the following in order to log both, stdout and stderr streams, by changing the entry like this. The change will simply append all log output to the /root/my_db_script.cron.log file:

# everyday at 03:00am run db script
0 3 * * * /root/my_db_script.sh > /root/my_db_script.cron.log 2>&1

Alternatively, we might as well simulate a cron environment by running bash with a limited environment (similarily to cron) in order to see what’s actually going on:

sudo su -c 'env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin/sh /root/my_db_script.sh' root
Leave a Comment : more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!