bkreynolds48
asked on
Cron runs script on Sunday when it is not supposed to
I have a cron entry to run a backup - it should not run on Sunday so I have "1-6" which should only run Monday through Saturday but it runs on Sunday as well. Can anyone tell me what I have wrong here?
Thanks!
00 15 1-30 * 1-6 /data7/nsr/bckhot.sh
Thanks!
00 15 1-30 * 1-6 /data7/nsr/bckhot.sh
please check which TZ is used for that user when it runs cron, also check TZ for root
ASKER
The timezone is GMT
00 15 1-30 * 1-6
If day-of-month and day-of-week are specified, cron treats this as an OR, so if either condition matches, the job will run.
A way to prevent this would to be to run the cron job every day-of-month (except the 31st, which you've excluded for some reason?) and then put something like this in the backup script:
if [ `date +%a` = "Sun" ]
echo "Sunday - skip backup"
exit 0
fi
Though I confess I don't see why you would exclude the 31st of the month - Why not just specify day-of-week 1-6 and replace day-of-month with *? (that's the exception to the OR rule)
If day-of-month and day-of-week are specified, cron treats this as an OR, so if either condition matches, the job will run.
A way to prevent this would to be to run the cron job every day-of-month (except the 31st, which you've excluded for some reason?) and then put something like this in the backup script:
if [ `date +%a` = "Sun" ]
echo "Sunday - skip backup"
exit 0
fi
Though I confess I don't see why you would exclude the 31st of the month - Why not just specify day-of-week 1-6 and replace day-of-month with *? (that's the exception to the OR rule)
tfewster, good eyes!
that's the parts of crontab's man page someone would read but forget thinking about it ...
that's the parts of crontab's man page someone would read but forget thinking about it ...
ASKER
I am skipping the "31st" because my tape library has only 30 tapes and I pull the tape by the day number and when the 31st comes I pull tape 15.
I will try you suggestion:
if [ `date +%a` = "Sun" ]
echo "Sunday - skip backup"
exit 0
fi
and see if this works for this coming Sunday.
Will let you know on Monday.
Thanks
I will try you suggestion:
if [ `date +%a` = "Sun" ]
echo "Sunday - skip backup"
exit 0
fi
and see if this works for this coming Sunday.
Will let you know on Monday.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.