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

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Script to toggle WAN

Discussion in 'Asuswrt-Merlin' started by CMc, Jun 3, 2020.

  1. CMc

    CMc Occasional Visitor

    Joined:
    Dec 1, 2018
    Messages:
    21
    In recent weeks I’m having issues with my ISP modem (virgin media SH3) dropping and out and failing to give my ASUS router a DHCP address.
    I can fix this by toggling the “Internet Connection” in main page.

    Can I put this into a script? I don’t know enough to write the script. I watched the log to see if I could commands sent when I manually cycled, but nothing showed worthwhile.

    then I can run this via SSH and could invoke via Siri Shortcuts. Saves family logging in and faffing etc

    off
    wait 5
    on

    Any ideas?
     
  2. Dabombber

    Dabombber Regular Contributor

    Joined:
    Apr 29, 2016
    Messages:
    195
    Should be possible with the command "service restart_wan". Service commands are mostly undocumented but you can poke around the source here and find them by searching for strcmp/strncmp.
     
    CMc likes this.
  3. Jeffrey Young

    Jeffrey Young Regular Contributor

    Joined:
    Dec 22, 2019
    Messages:
    93
    Location:
    Canada
    Add wan-event script in /jffs/scripts
    and build a script something like....

    Code:
    #!/bin/sh
    
    # variables passed to wan-event
    # $1 > Wan Adaptor
    # $2 > Wan state
    #               init
    #               connecting
    #               connected
    #               disconnected
    #               stopped
    #               disabled
    #               stopping
    
    if [ $2 == "disconnected" ]; then
      service stop_wan
      sleep <number of seconds>
      service start_wan
    fi
    
    Have not tested to see if I got all the bugs out, you may be able to issue service restart_wan without having to sleep first.
     
    CMc likes this.
  4. thelonelycoder

    thelonelycoder Part of the Furniture

    Joined:
    Jan 23, 2014
    Messages:
    7,009
    Location:
    Switzerland
    Without a sleep of about four seconds, the second _wan command would be skipped over as the first it still being run.
    I would use service restart_wan as the sole command and see if that fixes the problem.
     
    CMc, Jeffrey Young and L&LD like this.
  5. CMc

    CMc Occasional Visitor

    Joined:
    Dec 1, 2018
    Messages:
    21
    Thanks all. I’ll give it a go when it next drops