Results 1 to 13 of 13

Thread: Howto use cron for scheduling tasks

  1. #1
    Join Date
    Apr 2004
    Location
    Netherlands
    Posts
    1,308

    Howto use cron for scheduling tasks

    Everyone using this router for more than the usual stuff will get to a point where one or more tasks need to be scheduled to run once in a while. Unix/Linux provides the cron daemon to do this job and you can use it on the WL-500g as well.

    What you need:
    -The full busybox (from the downloads section of this forum)
    -An USB mass storage device like an USB pen or USB HDD

    Preparing the cron daemon:
    - The cron daemon needs a configuration file located in '/var/spool/cron/crontabs'. Create these directorys with 'mkdir'
    - Run the cron daemon with the following command (I assume the full busybox is in the root of your USB device): '/tmp/harddisk/busybox crondtab -e'. This will start the cron daemon in the configuration mode.
    - Add your daily tasks to the configuration file. Additional info can be found here: http://www.techtutorials.net/tutorials/unix/cron.shtml
    - Now the file created by crontabs holds the configuration. The filename is the username who started crontabs (e.g. 'admin'). This file needs to be restored between reboots using the flashfs system. Add the configuration file to /usr/local/.files (e.g. 'echo /var/spooler/cron/crontabs/admin >> /usr/local.files').

    Last step, running the daemon at each boot:
    To make sure the cron daemon is running after each reboot we need to put it into the /usr/local/sbin/post-boot script. Add the following line: '/tmp/harddisk/busybox crond'.

    Save the changes with the following commands: 'flashfs save' and 'flashfs commit' and reboot the router.
    Last edited by Styno; 23-01-2007 at 13:43. Reason: fixes, broken link reported by 'jam' (thanks!)

  2. #2
    Join Date
    Apr 2004
    Location
    Netherlands
    Posts
    1,308
    The above post describes the procedure for firmwares 1.8.x.x and higher. For 1.7.x.x replace '/tmp/harddisk' with '/mnt/usbfs'. That should do the trick.

  3. #3
    Since 1.9.2.7-1 crond is included in FW so there is no need for full busybox.
    To quickly summarize Styno's post:
    Code:
    mkdir -p /var/spool/cron/crontabs
    crontab -e
    #Edit crontab file. See tutorials on crontab and vi (text editor)
    #Ex. Press "a" for append-mode. Enter cron-command ex "00 1 * * * reboot" 
    #to reboot everyday at 1 am. Press "Esc", ":wq" and "Enter" to save and quit.
    mkdir -p /usr/local/sbin
    echo "/var/spool/cron/crontabs/admin" >> /usr/local/.files
    if [ ! -f /usr/local/sbin/post-boot ] ; then
    echo "#!/bin/sh" > /usr/local/sbin/post-boot
    fi
    echo "/usr/sbin/crond" >> /usr/local/sbin/post-boot
    chmod +x /usr/local/sbin/post-boot
    flashfs save
    flashfs commit
    #If not already enabled:
    flashfs enable
    reboot
    Edit:Fixed typo: spooler
    Edit2: Fixed typo2: crond instead of crontab.
    Edit3: Added "#!/bin/sh" to psot-boot if not existing.

    PS: These commands should only be run once. If they fail you need to edit .files and post-boot manually before you can try again..
    Last edited by barsju; 26-05-2005 at 09:31.

  4. #4
    hi,
    thanks for summarize this.
    ist this line ok ?
    Code:
    echo "/var/spooler/cron/crontabs/admin" >> /usr/local/.files
    or should it be
    Code:
    echo "/var/spool/cron/crontabs/admin" >> /usr/local/.files
    my problem is now that
    Code:
    crontab -l
    shows
    Code:
    59 4 * * * killall -1 pppd
    but at 4:59 nothing happend.

    What is wrong?
    Say if you need any more information.

    thanks for help
    Elron

  5. #5
    Oh. Yeah your right it should be:
    Code:
    echo "/var/spool/cron/crontabs/admin" >> /usr/local/.files
    I'll fix in original post!

    59 4 * * * killall -1 pppd
    How about:
    Code:
    59 16 * * * killall -1 pppd
    Or are you an earlybird?

    B.

  6. #6
    i mean 4:59 am

    i waited for more than 24 h but ther was only the normal 24h reconnect nothing at 16:59 or 4:59

  7. #7
    Sigh I had a second error in my code. echo "crontab".. shoud be echo "/usr/sbin/crond"..

    Once again I fixed the original thread!

    Sry for the mix up, and thanx to muffe that discovered it.
    S.
    Elron: You can check that crond is running with "ps"..

  8. #8
    i think i have found the problem
    i never crated the post-boot script
    so there was no "#!/bin/sh" in the first line of it
    found here

    with "ps" i can see this line "88 admin 392 S /usr/sbin/crond"
    now it shold work?

    other problem:
    cause of some faild "tries" to get cron working i see after "flashfs save" some errors
    Code:
    [admin@(none) root]$ flashfs save                                 
    tar: Removing leading '/' from member names                                           
    var/spool/cron/crontabs/admin                             
    var/spool/cron/crontabs/admin                             
    var/spool/cron/crontabs/admin                             
    tar: /var/spool/crontabs/admin: No such file or directory                                                         
    var/spool/cron/crontabs/admin                             
    tar: /var/spooler/cron/crontabs/admin: No such file or directory                                                                
    tar: /var/spooler/cron/crontabs/admin: No such file or directory                                                                
    tar: /var/spooler/cron/crontabs/admin: No such file or directory                                                                
    tmp/local/          
    tmp/local/sbin/               
    tmp/local/sbin/post-boot                        
    tmp/local/.files                
    tmp/local/root/               
    tar: Error exit delayed from previous errors                                            
    -rw-r--r--    1 admin    root          351 May 26 01:03 /tmp/flash.tar.gz                                                                         
    Check saved image and type "/sbin/flashfs commit" to commit changes
    how can i fix this?

    edit:
    system log show this line:
    "May 26 01:06:18 crond[88]: time disparity of 18617706 minutes detected"
    35 years?
    what means that line?
    Last edited by Elron; 26-05-2005 at 01:27.

  9. #9
    Well looks like you have some duplicate and wrong entries in /usr/local/.files
    Edit that file and remove entries.

    B.

    PS:Fixed script (again ) to include check for post-boot and add #!/bin/sh
    Last edited by barsju; 26-05-2005 at 09:36.

  10. #10
    Join Date
    Nov 2003
    Location
    Eindhoven
    Posts
    2,407
    Quote Originally Posted by elron
    system log show this line:
    "May 26 01:06:18 crond[88]: time disparity of 18617706 minutes detected"
    35 years?
    what means that line?
    well perhaps you just have booted up the router?

    at time of booting it is 1970.. until time synchronization

    My little Asus Collection: Too much to fit inhere, my 2 babies:WL500w 1.9.2.7-10(OLEG) VX2SE Yellow Lamborghini notebook



    WL500g Forum Asus Files OpenDir

    Asusforum.NL -- Asusforum.DE -- Asusforum.RU -- Asusforum.PL -- Asusforum.NET -- Asusforum.EU -- Asusforum.BE -- Asusforum.ES -- Asusforum.INFO

  11. #11
    thx @ all for help
    it works now

  12. #12
    Join Date
    Mar 2007
    Location
    Budapest / Hungary
    Posts
    79

    crontab error:

    Hi. Sorry my english.

    I use oleg 1.9.2.7-7f fw and I install ipkg package cron.
    When I try running crontab the system result this message:

    [admin@MYROUTER root]$ crontab -e
    You (admin) are not allowed to use this program (crontab)
    See crontab(1) for more information
    [admin@MYROUTER root]$

    I create cron.allow and insert admin but crontab not worked. What?

    Thanks, George

  13. #13
    Join Date
    Feb 2007
    Location
    Moscow, Russia
    Posts
    3,805
    It seems to me that this tutorial is a little bit obsolete. Better Use this one: http://www.macsat.com/macsat/content/view/28/29/

Similar Threads

  1. Easy-to use cron-system.
    By macsat in forum WL-500g/WL-500gx Tutorials
    Replies: 3
    Last Post: 29-05-2007, 22:18
  2. Script for scheduling pppoe connections?
    By Spot in forum WL-500g Q&A
    Replies: 4
    Last Post: 14-03-2005, 08:25

Posting Permissions

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