Script to reboot router if VPN fails

Discussion in 'Tomato Firmware' started by Hardrock, Sep 29, 2013.

  1. Hardrock

    Hardrock Networkin' Nut Member

    Hi Guys,

    I've been having a few issues with my VPN.. it seems to lock up a couple of times during a 24 hour period, and yet I can log into the E4200 router from my PC, and see my lease is still valid. The the VPN locks up, I can't ping any address until I physically reboot the router. I knocked up with a simple script below with the help of google, which I've placed in administration > Init.
    It pings google and the script is called by the scheduler every 5 mins. I did the pingtest.log to check it was logging, this kind of works but I did note that the date and time is always the same in the log??

    If i switch off my cable modem, the router does not reboot... so the sbin/reboot does not seem to work in the script.. Any ideas guys what I can do to fix this? I just want to keep it simple :)

    cat > /tmp/ << MARK1
    ping -c 1 > /dev/null
    if [ $? -ne 0 ];
    #echo "Ping failed, rebooting `date +%d%m%Y%H%M`" >> /tmp/pingtest.log
    echo "Ping fine, sleeping `date +%d%m%Y%H%M`" >> /tmp/pingtest.log
    chmod a+x /tmp/
    Last edited: Sep 29, 2013
  2. koitsu

    koitsu Network Guru Member

    Your script makes egregious assumptions about the state of the Internet -- meaning: you are assuming a single ICMP packet will reach (some server at Google) at all times, 100% reliably. This is not the case. The Internet is usually broken 24x7x365 in some way. Check out the nanog and outages mailing lists for proof.

    Try pinging something closer to you (such as the IPv4 gateway address delegates to you, or better yet, one of your ISP's DNS servers), and ping for a longer period of time -- say 10 packets, and only reboot if a certain percentage of loss is exceeded.

    BTW, the reason the script always has the same date/time is because of how you're creating the script. The backticks around date, i.e. `date ...` are being interpreted within the shell that is spawning cat, meaning the date is hard-coded into /tmp/ The only way you're going to be able to deal with this is potentially by escaping the backticks, but this might also not work. My advice is to stop creating scripts in /tmp at boot-up and instead get a USB stick with a filesystem on it to keep scripts/tools/etc. that you need persistently.

    I choose not to assist past this point in time.
  3. Hardrock

    Hardrock Networkin' Nut Member

    Thank you Koitsu... you may note that I am a beginner in all this, so please do not go to hard at me! I've used google to get me so far, but understand what you are saying. If anyone has a working script specifically written to monitor a router VPN, please share :)
  4. scoobynz

    scoobynz Networkin' Nut Member

    Hi Hardrock,

    I am interested in your work. I too have similar issues with the VPN crashing periodically. . . . In my case the symptoms are a failure of DNS. In any instance, I would be interested in progress of your script. . .
  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