| Crobtab Tutorial |
|
|
|
| Written by macsat | |
| Friday, 25 November 2005 | |
|
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 : If you are the lucky owner of any of the above devices, you have come to the right place. 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 Index1. Prerequisites - What is needed to get started.2. Installing and Configuring cron PrerequisitesAll you need is :I consider your setup to be simular to the setup I created in the ipkg Tutorial Installing and Configuring cronAs usual the joint efforts of Oleg, The Slug guys and others in the community, installing the software is very easy : 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 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 : 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 : 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 : 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: #!/bin/sh Remember to chmod the script to be executable : # # runparts.sh by This e-mail address is being protected from spam bots, you need JavaScript enabled to view it # 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 chmod +x /opt/bin/run-parts 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 : #!/bin/sh date >> /tmp/crontest.txt Remember to make it excutable : 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 I hope you found this tutorial useful. |
|
| Last Updated ( Tuesday, 10 January 2006 ) |
| < Prev | Next > |
|---|







