Find the answer to your Linux question:
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. ...
  1. #1
    Just 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

  2. #2
    Just Joined!
    Join Date
    Jul 2008
    Posts
    81
    Quote Originally Posted by juju69 View Post
    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
    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.

  3. #3
    Just Joined!
    Join Date
    Mar 2007
    Posts
    3
    Quote Originally Posted by juju69 View Post
    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
    The day of the month and day of the week fields are OR'd, not AND'd.

    You need a * in the day of week field to accomplish your task.
    Also, in the script field, : [ "$(date '+%a')" == "Thu" ] && runscript.sh

  4. #4
    Just 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,

  5. #5
    Linux Enthusiast Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    717
    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

  6. #6
    Just 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.

  7. #7
    Linux Enthusiast Kloschüssel's Avatar
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    717
    Code:
    crontab -e
    This 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:
    [ "$(date '+%a')" == "Thu" ] && <script>
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...