Results 1 to 7 of 7
Hello,
i want schedule a task in crontab, but I don't now what is wrong.
my crontab file:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
...
- 04-26-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 3
Problem with crontab
Hello,
i want schedule a task in crontab, but I don't now what is wrong.
my crontab file:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXXtG8dVq installed on Thu Apr 22 10:11:36 2010)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
#!/bin/sh
0 10 1-7 * 4 /root/faxfiledocq.sh
10 10 1-7 * 4 /root/faxfiledoneq.sh
20 10 1-7 * 4 /root/faxfileinfo.sh
30 10 1-7 * 4 /root/faxfilelog.sh
i have set 1-7 for running only in the 7 firth day * for all month and 4 for Thursday, my script running all Thursday and i want to run only the first Thursday of month.
Tanks
- 04-27-2010 #2Just Joined!
- Join Date
- Jul 2008
- Posts
- 81
This is a problem that people have had with crontab for decades. If you read the manual page carefully, you will see that the selection for day-of-month and the selection for day-of-week are combined in OR fashion. Thus the program is doing exactly what you asked it to, running on days 1-7 and also running on Thursday.
The usual solution is to write a shell script that is called from crontab on days 1-7. Then have that script check whether the day is Thursday, and run the program of your choice if so, otherwise do nothing.
- 04-27-2010 #3Just Joined!
- Join Date
- Mar 2007
- Posts
- 3
- 04-27-2010 #4Just Joined!
- Join Date
- Apr 2010
- Posts
- 3
Thanks you for reply, it is a very good solution.
i have modify my crontab, and i wait to see !
#!/bin/sh
0 10 1-7 * * [ "$(date '+%a')" == "Thu" ] && /root/faxfiledocq.sh
10 10 1-7 * * [ "$(date '+%a')" == "Thu" ] && /root/faxfiledoneq.sh
20 10 1-7 * * [ "$(date '+%a')" == "Thu" ] && /root/faxfileinfo.sh
30 10 1-7 * * [ "$(date '+%a')" == "Thu" ] && /root/faxfilelog.sh
Thank you very much.
juju,
- 04-27-2010 #5
You don't seem to have any kind of experience with the anacron daemon, so I really recommend you to read the crontab and cron man pages. If you don't know what man pages are, use a search engine.

PS: don't try to edit files with less, more or other editors manually, this usually results in a lot of trouble
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXXtG8dVq installed on Thu Apr 22 10:11:36 2010)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
#!/bin/sh
- 04-27-2010 #6Just Joined!
- Join Date
- Apr 2010
- Posts
- 3
Kloschüssel thank you for your council, i use crontab -e for edit and -l for read.
i work very few time on linux system, because in my job they have many windows.
- 04-28-2010 #7This is the way to edit crontabs, it starts the default editor and installs the new crontabs when you have written the change and exit it. So you accomplished lesson 1-3 of the "learn unix in 3 days" how to.Code:
crontab -e

I would recommend you to use %w instead of %a. %w is the day of week in numeric form and not localized. The value ranges [0..6] where 0 is sunday. The rest seems to be perfectly fine.Code:[ "$(date '+%a')" == "Thu" ] && <script>


Reply With Quote
