Custom Tomato script

Discussion in 'Tomato Firmware' started by Urko, Jan 27, 2007.

  1. Urko

    Urko Network Guru Member


    I'm using a cable modem to connect to internet and sometimes my connection goes down, then internet isn't working. On the Status - Overview tab it says connected and IP are shown. But when i trie to ping some site, the server isn't responding, internet isn't working. After i click Renew button, it takes about 5s and the internet is working again.
    Now the question.

    Is it possible to write some kind of script that would ping some site(watchdog) on interval about 5min and if there wouldn't be any response the router would renew it's connection or rebooted it self?

    Thans for your time.
  2. GeeTek

    GeeTek Guest

    I know there are stand alone products that are made to power-cycle if they do not get ping responses. I can find some links if you are interested. A script for Tomato would be best.
  3. ntest7

    ntest7 Network Guru Member

    I use something like this for my "init" script. administration->scripts->init

    # seconds between checks
    # hostname or IP to ping

    while sleep $WATCHDOG_SLEEP_SEC
    if ping -c 1 $WATCHDOG_SITE > /tmp/null
    echo "$WATCHDOG_SITE ok"
    logger "$WATCHDOG_SITE missed ping"
    sleep 4
    if ! ping -c 1 $WATCHDOG_SITE > /tmp/null
    logger "$WATCHDOG_SITE down, refreshing DHCP"
    killall -SIGUSR2 udhcpc
    sleep 2
    killall -SIGUSR1 udhcpc
    done 2>&1 &
  4. der_Kief

    der_Kief Super Moderator Staff Member Member

    Maybe a cron job like this

    cru a watchdog "0-59/5 * * * * ping -c 3"

    will do it for you.Make a telnet or ssh an put this line in. And dont forget to put this line also to init script.

  5. Urko

    Urko Network Guru Member

    Thank you guys for help.
    I'll tred ntest7 script tonight and then 'll report sucess.
    I add thi script to administration->scripts->init , press save and that's it ? Do i must reboot before changes'll make efect?
    Thanks again.
  6. Urko

    Urko Network Guru Member

    Does anyone knows with wich command I could see how many connections each ip has opened?
  7. digitalgeek

    digitalgeek Network Guru Member

    In advandced, Conn Track you can see total number of active connections. If you have QOS enabled you can look at details and see connects in each category. (Clicking on a category in the graph will show specific categories connections)
  8. ntest7

    ntest7 Network Guru Member

    You'll need to reboot for the script to run. Your log (if enabled) will show when a ping is missed and when a DHCP renewal is triggered, but not successful pings.
  9. Int15

    Int15 Network Guru Member

    I have this in my "WAN UP" script:

    #START: Reboot on signal loss
    sleep 60
    while [ "`ping -c 3|grep 100%`" == "" ]
    sleep 600
    #END: Reboot on signal loss
    Now, I have two questions, because I'm really unfamiliar with linux.

    1) This script looks far simpler compared to the one from ntest7. Is it doing the same thing?

    2) I usually put my scripts in Wan Up, because they didn't use to work in Init (Tomato v1.0). Was that fixed?


  10. snwbdr

    snwbdr Network Guru Member

    Got this from the FAQ

  11. ntest7

    ntest7 Network Guru Member

    This script will reboot the router when the specified IP is unavailable, which will also cause all wireless clients to drop connection temporarily.
    This script also requires that all pings are successful, so temporary network glitches will force a reboot.

    The script I posted earlier simply releases and renews the DHCP IP address, and is slightly fault tolerant in that it gives the remote IP a second chance to respond before any action is taken. This is also less disruptive for connected clients, so it's safe to run the script frequently.

    Rebooting the router will address a wider range of problems, such as if the network stack or firewall gets wedged somehow, but those things rarely happen with stable software. If the whole router is locked, neither script will help. If your router hardware is flaky, the rebooting script may help.
  12. Int15

    Int15 Network Guru Member

    Thanks a lot for the explanation!
    I will change the script and use yours instead.

  13. Urko

    Urko Network Guru Member

    I am using a script from ntest7 and Linksys54GL. I noticed that i have sometimes only 300KB free memory of 14.2MB.
    I used comand top in telnet and it gives me this.
    Mem: 13948K used, 592K free, 0K shrd, 1524K buff, 4992K cached
    Load average: 0.08 0.13 0.09  (Status: S=sleeping R=running, W=waiting)
        3 root     SWN        0     1  7.6  0.0 ksoftirqd_CPU0
     6301 root     R        372  6026  4.2  2.5 top
      103 root     S        304     1  1.7  2.0 rstats
     1363 nobody   S        484     1  0.0  3.3 dnsmasq
     1438 root     S        476     1  0.0  3.2 upnp
        1 root     S        468     0  0.0  3.1 init
     6026 root     S        444    82  0.0  3.0 sh
      246 root     S        420     1  0.0  2.8
     1517 root     S        420     1  0.0  2.8
      106 root     S        396     1  0.0  2.7 httpd
       98 root     S        368     1  0.0  2.5 crond
      216 root     S        364     1  0.0  2.4 udhcpc
       82 root     S        288     1  0.0  1.9 telnetd
       20 root     S        260     1  0.0  1.7 buttons
     5717 root     S        232   246  0.0  1.5 sleep
     1758 root     S        232  1517  0.0  1.5 sleep
        7 root     SW         0     1  0.0  0.0 mtdblockd
        2 root     SW         0     1  0.0  0.0 keventd
       86 root     SW         0     1  0.0  0.0 cifsoplockd
        6 root     SW         0     1  0.0  0.0 kupdated
        4 root     SW         0     1  0.0  0.0 kswapd
        5 root     SW         0     1  0.0  0.0 bdflush
    I think i would free up some memory if would run only one process not two.
    Oh, one more thing, some times router doesn't work poroperly if free memory is only 200KB, some pages doesnt open.
    Thanks anyone who would see the solution.
  14. psychowood

    psychowood Network Guru Member

    About running twice I think there is something wrong (like a script that enters a loop forever, but runned twice because your wan restarted once), but it isn't eating so much ram, just 2.8% more (less than 400K).
    Your free ram isn't that bad, consider that there are almost 5000KB used as cache, those are freed as soon as some memory is needed.

    In Administration -> Miscellaneous you can check "Count cache memory as free memory" to have a more realistic stat about your free ram. :)
  15. Urko

    Urko Network Guru Member

    Thank you. I realy didn't know that.
  16. danix71

    danix71 LI Guru Member

    How about a script on a bridge that check if a ping on an external address (for ex: is succesfull (so there is a connection to the Internet on that very bridge) and then SES white is shown?
    Can somebody help? Thanks!
  17. lfjeff

    lfjeff Networkin' Nut Member

    This is what I've been using for years...
    GW=`nvram get wan_gateway`
    IF=`nvram get wan_ifname`
    if ! ping -q -c 5 -w 30 $GW
      logger "Lost WAN connection, attempting to renew DHCP..."
      udhcpc -i $IF -q -S
      ddns-update 0 force
    I have it set up under "Administration -> Scheduler -> Custom 1" and it runs every minute.
  18. Roy gallo

    Roy gallo Network Newbie Member

    sorry to fire up an old topic but what is the capital S switch in that line do. I cant find mention of it anywhere

    "udhcpc -i $IF -q -S"

    disregard I found it lol
  19. pppddd

    pppddd Serious Server Member

    -S,--syslog Log to syslog too
  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