1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

3G Watchdog script

Discussion in 'Tomato Firmware' started by kyrios, Jan 26, 2013.

  1. kyrios

    kyrios Serious Server Member

    Anyone has working script for auto reconnect?
    There's a script but it's for OpenWRT. I just do not know how to port into Tomato.

    Create file
    # touch /bin/tester.sh
    # chmod 755 /bin/tester.sh

    Write this into:
    #!/bin/sh
    if ! ping -q -c 1 -W 10 8.8.8.8 > /dev/null; then
    (ifup wan) &
    fi

    Create CRON:
    # /etc/init.d/cron stop
    # echo "*/2 * * * * /bin/tester.sh" >> /etc/crontabs/root
    # /etc/init.d/cron enable
    # /etc/init.d/cron start

    Someone please?
     
  2. kyrios

    kyrios Serious Server Member

    OK, back to Tomato Toastman.
    I then encounter the same problem.
    3G is connected but no data (ul/dl) flows.
    It seems Connect Mode: Keep Alive menu does not work correctly.

    I then have an idea to port above code from OpenWRT into Tomato.
    Since I'm noob, I encounter many hard problems.

    1. Tomato firmware is read only
    Code:
    Create file
    # touch /bin/tester.sh
    # chmod 755 /bin/tester.sh
     
    Write this into:
    #!/bin/sh
    if ! ping -q -c 1 -W 10 8.8.8.8 > /dev/null; then
    (ifup wan) &
    fi
    OK, I activated JFFS in Tomato and can make such file (tester.sh)

    2. There's no init.d/cron dir in Tomato
    Code:
    Create CRON:
    # /etc/init.d/cron stop
    # echo "*/2 * * * * /bin/tester.sh" >> /etc/crontabs/root
    # /etc/init.d/cron enable
    # /etc/init.d/cron start
    Hm... I have clueless.

    Then I realize that Tomato has scheduler script.
    Administration => Scheduler => Custom 1
    Enabled => (thicked)
    Time => Every minute
    Command => ....
    My question is:
    Can I write this?
    Code:
    if ! ping -q -c 1 -W 10 8.8.8.8 > /dev/null; then (service wan restart) &
    fi
    Will above code work?
     
  3. jerrm

    jerrm Network Guru Member

    At first glance it should work, but I wouldn't base it on just a single ping, you'll likely be restarting when you don't need to.
     
  4. mvsgeek

    mvsgeek Addicted to LI Member

    At the risk of once again offending the coding purist(s);) , here's the script I posted during last month's "lost window" of forum activity...

    Code:
    #!/bin/sh
    # Script to monitor and reboot secondary routers when needed
     
    maxPloss=99 # Maximum percent packet loss before a reboot
    pingtime=15 # Default number of seconds to keep pinging
     
    # Initialize to a value that would force a reboot
    # (just in case ping gives an error and ploss doesn't get set)
     
    ploss=101
     
    # If no target router specified, default to 192.168.1.1 
     
    trip="192.168.1.1"
     
    if [ "$1" != "" ]; then
        trip="$1"
    fi 
     
    if [ "$2" != "" ]; then
        pingtime="$2"
    fi 
     
    # now ping target router for specified number of seconds and count packet loss
     
    ploss=`ping -q -w$pingtime $trip | grep -o "[0-9]*%" | tr -d %` > /dev/null 2>&1
     
    if [ "$ploss" -gt "$maxPloss" ]; then
          logger No response from $trip - rebooting... 
          reboot 
    fi
     
    exit 0 
    Output from the logger command is lost if the router doesn't have the capability to preserve log files across reboots.

    I save this script as /jffs/bin/ping_ap.sh and then invoke it by adding the following in administration/scripts/init to create the relevant cron job :

    Code:
    cru a keepalive "*/5 * * * * /jffs/bin/ping_ap.sh 192.168.1.1 20"
    A reboot to create the cron job can be avoided by executing the above command from either tools --> system or an ssh session.

    I've found that in a WDS environment, it's necessary to run a corresponding script on the main router, which invokes nas4not for any unresponsive WDS slaves. I'll post that script if there's any interest.
     
    kyrios likes this.
  5. kyrios

    kyrios Serious Server Member

    @mvsgeek:
    Code:
    cru a keepalive "*/[B]5[/B] * * * * /jffs/bin/ping_ap.sh [B]192.168.1.1[/B] 20"
    5: is it 5 minutes of scheduler script?
    192.168.1.1: Can I replace with google DNS (8.8.8.8)?
     
  6. mvsgeek

    mvsgeek Addicted to LI Member

    1. The command as written creates a cron job which runs every 5 minutes.
    2. Yes. The first argument can be any IP address of your choice - default is 192.168.1.1
     
  7. kyrios

    kyrios Serious Server Member

    @mvsgeek:
    Forget to ask you this.
    The 20 behind 192.168.1.1 is?
     
  8. mvsgeek

    mvsgeek Addicted to LI Member

    It's the number of seconds to ping the target before deciding whether it's responding. Default is 20.
     
  9. kyrios

    kyrios Serious Server Member

    THX U :)
     

Share This Page