-   Linux - General (
-   -   cron job running at unexpected times (

prl77 05-29-2012 01:33 PM

cron job running at unexpected times

#cat /etc/cron.d/script1
03 20 08 05 2 root /root/ 2>&1 >/dev/null

Two problems:
  1. I only intended to run this script one time, but it runs every Tuesday for some reason. I have other machines with similarly narrowed down schedules and they work as expected.
  2. I'm redirecting output to /dev/null to not receive an email. I know I can also use the MAILTO="" directive, but I'm pretty sure I've successfully used this method in the past.

Thank you for your time everybody.

pan64 05-29-2012 01:38 PM

there are a few problems:
you need to write redirection as:
03 20 08 05 2 root /root/ >/dev/null 2>&1 (this will redirect stderr to stdout and than stdout to /dev/null) otherwise you will redirect stdout to /dev/null and stderr to stdout.
The number 2 before root (fifth field) means you want to execute it on every Tuesday (see man page of crontab)

rknichols 05-29-2012 01:45 PM

Your claims of other machines working as expected notwithstanding, the manpage for the crontab file (`man 5 crontab`) quite clearly states:

Note: The day of a commandís execution can be specified by two fields ó day of month, and day of week. If both fields are restricted (ie, arenít *), the command will be run when either field matches the current time. For example, "30 4 1,15 * 5" would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.

prl77 05-29-2012 06:41 PM

Thank you gentlemen. Upon further examination, I do see that the other jobs I referenced as working as expected, were in fact running every week, I just didn't realize it because there was nothing for them to do during that time frame. This was a good lesson, my understanding of the crontab table format was incorrect, I thought all restricted (non *) fields had to match.

All times are GMT -5. The time now is 09:22 PM.