Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have a cron job under a specific user's crontab which should be running only on working week days. Job was running all days before we changed it.

After we changed in the following line the days statement from '*' to '1-5', testscript.sh is still running all days and the weekend that is not supposed to.

00 21 * * 1-5 /usr/local/bin/test_script.sh >> /var/log/userdirectory/test_script.log 2>&1

Any ideas why?

share|improve this question
    
00 21 * * 1-5 instead of this can you try 0 21 * * 1-5 and check if this works or not. –  Abhishek Anand Amralkar Sep 30 '13 at 13:05
3  
The '00' versus '0' in the first column has nothing to do with the problem. How did you edit the crontab file, via vi or via crontab -e or some other way? –  John Sep 30 '13 at 13:18
    
We had changed it in /var/spool/cron/crontabs/usercronjobs and then with crontab -e. –  fotag Oct 1 '13 at 11:14
    
Fixed with deletion and recreation of the specific line via crontab -e. Maybe this line inserted there without crontab -e and hasn't installed correctly. Anyway, thanks for your ideas! –  fotag Dec 11 '13 at 10:59

1 Answer 1

Well, the most likely case is that something went wrong when you were updating crontab. If you can't track down the specific issue, there's an easy workaround: in test_script.sh, add a couple of lines to quit if it's not one of the correct days for running the script. Something like:

#quit if we're doing this on the wrong day of the week
if date | grep Sun &> /dev/null
then
exit 0
fi
if date | grep Sat &> /dev/null
then
exit 0
fi

(yes, I know there's better ways to do those statements; this is just a way to do it that is really easy to understand and see what it's doing)

share|improve this answer
    
Thanks for your answer! I think will try sth like this until we find out what is going there –  fotag Oct 3 '13 at 12:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.