Warning: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in ..../includes/class_bootstrap.php(430) : eval()'d code on line 123
Easy-to use cron-system.
Results 1 to 4 of 4

Thread: Easy-to use cron-system.

  1. #1

    Easy-to use cron-system.

    ASUS WL-Series XXXXXX Tutorial

    The guide is made using a ASUS WL-500G Deluxe (or WL-500GX as it is sometimes called).
    It should however apply to all the ASUS wireless line of products that are Linux based. Theese products are to my knowledge :

    ASUS WL-500b
    ASUS WL-500bv2
    ASUS WL-500g
    ASUS WL-500g Deluxe (WL-500gx)
    ASUS WL-HDD
    If you are the lucky owner of any of the above devices, you have come to the right place.
    If you still dont have one of the above devices - dont hesitate, go buy one :-)

    After following the steps in this tutorial, your ASUS WL device will have all its normal functionality, and also enable you to run sheduled tasks at specified intervals.

    When running a server it is often nice to be able to run specific tasks at pre-defined intervals. Sometimes it is nice to be able to strip logs every day, check for internet connection every 5 minutes or do something else every XX minutes/hours/days/weeks/months.

    After following this tutorial you will be left with an easy-to-use crontab based system, that enables you to run tasks at specified intervals, with no knowledge about cron.
    The system is somewhat simular to the crontab implementation of RedHat

    Tutorial Index
    1. Prerequisites - What is needed to get started.
    2. Installing and Configuring cron



    Prerequisites
    All you need is :

    One of the above Asus Wireless devices
    An USB Harddrive or USB Memory Stick / Keyring with some 50-100 MB space.(For the WL-HDD you just need a regular Harddrive)
    Firmware version 1.9.2.7-4 (or higher) by Oleg

    I consider your setup to be simular to the setup I created in the ipkg Tutorial




    Installing and Configuring cron
    As usual the joint efforts of Oleg, [http://www.nslu2-linux.org/]The Slug guys and others in the community, installing the software is very easy :
    Code:
    ipkg install cron < enter >
    This will install the cron demon, and even install the startup script in /opt/etc/init.d/
    If you have followed my setup in the ipkg Tutorial cron will automaticly start at boot time

    Since crontab can be a pain to use for non-vi-Lovers, lets create a few dirs, where we can place scripts that can be ran at specified times
    Code:
    mkdir /opt/etc/cron.5mins 
    mkdir /opt/etc/cron.hourly 
    mkdir /opt/etc/cron.daily 
    mkdir /opt/etc/cron.weekly 
    mkdir /opt/etc/cron.monthly
    In the above directories .sh scripts can now be placed, and after following the remaining few steps of this guide, they will run at pre-specified points in time

    Now use your favourite editor to change the file: /opt/etc/crontab to be something like this :
    Code:
    SHELL=/bin/sh 
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin 
    MAILTO="" 
    HOME=/ 
    # ---------- ---------- Default is Empty ---------- ---------- # 
    # Syntax for lines is : minute hour day month dayofweek command # 
    */5 * * * * root run-parts /opt/etc/cron.5mins 
    01 * * * * root run-parts /opt/etc/cron.hourly 
    02 4 * * * root run-parts /opt/etc/cron.daily 
    22 4 * * 0 root run-parts /opt/etc/cron.weekly 
    42 4 1 * * root run-parts /opt/etc/cron.monthly
    Notice: In the above I have used "root". This should be changed to the login name that you use on the web interface of yor router. Default name for the ASUS devices is "admin".

    As also noted in the file, the syntax for each line is : minute hour day month dayofweek command
    To take an example, the command: run-parts /opt/etc/cron.weekly is executed at time :
    Code:
    minute : 22 
    hour : 4 
    day : * 
    month : * 
    dayofweek : *
    Where "*" is a wild-card meaning "ALL".
    Thus the command is running : Every day of week, Every Month, Every Day at 4:22
    Note that cron uses a 24h clock.

    This means that 4:22 is 4:22 AM, 4:22 PM would be indicated as :

    Code:
    22 16 * * 0 root run-parts /opt/etc/cron.weekly
    The special */5 in the first line, means that this job is executed every 5 mins. At the minutes 5, 10, 15.....55.

    Having created this config-file, all that is needed is the command "run-parts" which is not a part of the firmware.
    For this purpos I created a small script which I named run-parts and placed in /opt/bin
    A script like this will do the job:
    Code:
    #!/bin/sh 
    # 
    # runparts.sh by macsat@macsat.com 
    # intended for use with cron 
    #
    # based on rc.unslung by unslung guys :-)
    #
    if [ -z "$1" ]
    then 
    echo "Usage : $0 "
    fi
    
    RUNDIR=$1"/*"
    
    for i in $RUNDIR ;do
    
    # Ignore dangling symlinks (if any).
    [ ! -f "$i" ] && continue
    
    case "$i" in
    *.sh)
    # Source shell script for speed.
    (
    trap - INT QUIT TSTP
    set start
    . $i
    )
    ;;
    *)
    # No sh extension, so fork subprocess.
    $i start
    ;;
    esac
    done


    This should be it!

    In order to test the cron-system, you could try to make a small script in /opt/etc/cron.5mins called test.sh, like this :
    Code:
    #!/bin/sh
    
    date >> /tmp/crontest.txt

    Remember to make it excutable :
    Code:
    chmod 755 /opt/etc/cron.5mins/test.sh
    Try to reboot your router and let it run for some 10 or 15 minuts. Then you should see a list of timestamps in :
    /tmp/crontest.txt

    showing when the cron has been running the script
    macsat
    http://www.macsat.com - Tutorials and information on using ASUS WL-500G and family.

  2. #2

    Lightbulb needed a few changes

    Hello macsat,

    thanx for yet another clear and well written howto!

    I had to make some minor ajustments however, to get it running on my wl500g running oleg's 1.9.2.7-6b.

    First of all I made /opt/bin/run-parts executable using
    Code:
    chmod 755 /opt/bin/run-parts
    after creating it as you described.

    next, although cron was running nicely, judging from the syslog:
    Code:
    Jul 30 00:01:01 /opt/sbin/cron[193]: (****) CMD (run-parts /opt/etc/cron.hourly )
    but no crontest.txt appeared in /tmp.

    I had to change /opt/etc/crontab from running run-parts to running /opt/bin/run-parts, like this:

    Code:
    SHELL=/bin/sh
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=""
    HOME=/
    # ---------- ---------- Default is Empty ---------- ---------- #
    # Syntax for lines is : minute hour day month dayofweek command #
    */5 * * * * rootloginuser /opt/bin/run-parts /opt/etc/cron.5mins
    01 * * * * rootloginuser /opt/bin/run-parts /opt/etc/cron.hourly
    02 4 * * * rootloginuser /opt/bin/run-parts /opt/etc/cron.daily
    22 4 * * 0 rootloginuser /opt/bin/run-parts /opt/etc/cron.weekly
    42 4 1 * * rootloginuser /opt/bin/run-parts /opt/etc/cron.monthly
    Now everthing works like a charm

    O, and by the way, "vi" is not so hard to learn

    regards,
    CThings
    Last edited by cthings; 29-07-2005 at 23:35. Reason: Oeps olec = oleg, sorry

  3. #3
    You are right about the missing chmod on the run-parts script, I will correct that ASAP :-)

    Regarding the need for full path to "run-parts" in the cron script, you have used a different "path line" than I have, You have :
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    While I have :
    PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin
    This is the reason why it didnt work for you before writing the full path to run-parts :-)
    macsat
    http://www.macsat.com - Tutorials and information on using ASUS WL-500G and family.

  4. #4
    Join Date
    Nov 2004
    Location
    Sweden
    Posts
    259

    cron questions...

    2 questions:

    1) Is there any way to avoid cron adding entries in syslog?
    2) Is there any way to configure cron to specify where to create file cron.pid? -> is it hard coded /opt/var/run/cron.pid ?

    ANSWER QUESTION 2
    ================
    As a workaround I have created a symlink in directory /opt/var called "run" pointing to my desired destination folder. E.g.
    rmdir /opt/var/run
    ln -s /myfolder /opt/var/run
    Last edited by Tamadite; 29-05-2007 at 22:54.

Similar Threads

  1. RRDTool Traffic Graph Tutorial - Extremely easy to follow !
    By macsat in forum WL-500gP Tutorials
    Replies: 83
    Last Post: 09-06-2009, 21:34
  2. Howto use cron for scheduling tasks
    By Styno in forum WL-500g/WL-500gx Tutorials
    Replies: 12
    Last Post: 27-04-2007, 11:10

Posting Permissions

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