kaid and cron

Discussion in 'HyperWRT Firmware' started by fabjan, Jan 12, 2005.

  1. fabjan

    fabjan Network Guru Member


    I'm using kaid demon on my WRT54G but sometimes the process crash. So I wrote the following startup script to monitor the process and restart it when it is crashed :
    sleep 10
    wget http:/mywebsite/kaid -O /tmp/kaid
    wget http://mywebsite/kaid.conf -O /tmp/kaid.conf
    chmod +x /tmp/kaid
    echo "#!/bin/sh" > /tmp/chk_k.sh
    echo "while true" >> /tmp/chk_k.sh
    echo -e 'if [ `ps | grep -c kaid` -lt 3 ]; then /tmp/kaid -d -c /tmp/kaid.conf; fi;' >> /tmp/chk_k.sh
    echo "sleep 60" >> /tmp/chk_k.sh
    echo "done" >> /tmp/chk_k.sh
    chmod +x /tmp/chk_k.sh
    /tmp/chk_k.sh &

    This script download kaid and kaid.conf from my website and enable to execute kaid, then create a scritp /tmp/chk_k.sh and start it.
    Here is the /tmp/chk_k.sh :

    while true
    if [ `ps | grep -c kaid` -lt 3 ]; then /tmp/kaid -d -c /tmp/kaid.conf; fi;
    sleep 60

    There is no problem, everything works fine, but I would like to run the script whith a crontab, not within a while loop. My question is about the crontab. I don't understand how it works. I can see a cron demon in the list of running process, and a /tmp/con.d/check_ps which contain */2 * * * * root /sbin/check_ps.
    How to add a new script in a crontab ? Create a new file in the cron.d folder and do "cron /tmp/cron.d/mycrontab" ? But then, what about the check_ps ?

    Any ideas ?


  2. PinPin

    PinPin Network Guru Member

    You may place your (executable) script in /tmp/cron.d/ but you will have to restart cron daemon.

    There is another way to do that with cron -e (cron editor) and add a line like:

    * * * * * /tmp/kaid -d -c /tmp/kaid.conf > /dev/null 2>&1

    Then exit the editor using -> ESC -> wq -> Enter.

    As I understand, kaid is not in openwrt rom so you have to do the whole installation on every reboot ? I think your script is easier than modifying cron but I would rather place the whole bunch of command into a master shell script and I will simply wget it to the box.

    You could also use init and its inittab configuration file but that is another story...

    Hope this helps :p
  3. fabjan

    fabjan Network Guru Member

    Hi PinPin,

    Thank you for your answer. You are right, it would be easier to wget the script than recreate it with the echo commands. I'll do that.
    Can you explain how the init ant inittab system ?

    Thanks again

  4. PinPin

    PinPin Network Guru Member

    Ok, here are some explanations regarding init but if you have access to a Linux machine the 'man' command is your friend e.g.: 'man init' will give you a bunch of information regarding the init process.

    When a *Nix like system starts, the first process to be launched is 'init' it is also known to be the father of all process, its pid is always 1.

    /etc/inittab is the configuration file for init, it defines a lot of things like the different runlevel, the process to start on boot time, ...

    In your case an interesting line is the default run level, you should find something like : id:2:initdefault: which says the default run level is set to 2 -> we will use this runlevel for kaid.

    Each line you find in init has the following syntax:


    id is whatever you want with 4 characters maximum (it's like a unique key in inttab)

    There are different available actions (in our case respawn is interesting) so will place a line like that in /etc/inittab:

    kai:2:respawn:/tmp/kaid -d -c /tmp/kaid.conf

    Adapt the previous example to your needs cause I don't own a WRT54G so I can't see how it works with HyperWRT...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice