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

scripting question

Discussion in 'Tomato Firmware' started by lupinnktp, Oct 17, 2009.

  1. lupinnktp

    lupinnktp Addicted to LI Member

    i've tomato, and i'm familiar w the firmware. i use QoS 24/7 and blah blah. however, i lack scripting experience. Now i want to accomplish this task:

    i've computer assigned specific IP. I want it such that if computer A is disconnected (either by turning it off, or LAN cable unplugged) then the whole router freezes or the internet access is disabled.

    i'm thinking of doing a ping to computer A every 15 minutes. and if there is no successful ping then a command will be carried out.

    Could anyone draft me such script? or point me in some direction, plz?
  2. ntest7

    ntest7 Network Guru Member

    Something like this might work... Put this in the Administration-Scripts-Startup page on tomato. Replace the IP with the host you want to monitor.

    Discussion - the "ifconfig vlan1 up|down" will enable|disable the internet connection. The "killall -SIGUSR1 udhcpc" renews the external DHCP lease and is required for a down->up transition. That part can be removed if you have a static internet IP.

    All this should be a no-op on an already-up interface, but I'm not confidant how all ISP's will respond to this -- some could give you a new IP unnecessarily.

    No warranty, untested. But at least this gives you an idea of how something like this can be done.

    # disable internet when logging PC is unreachable
    while /bin/sleep 60 ; do 
    if ping -c 1 >/dev/null 2>&1
       then /sbin/ifconfig vlan1 up
              /usr/bin/killall -SIGUSR1 udhcpc
       else /sbin/ifconfig vlan1 down
    done >/dev/null 2>&1 &
  3. TexasFlood

    TexasFlood Network Guru Member

    You could start with the connection keepalive script I posted here. Some items you might like to adjust, such as run frequency, are listed in that post. For your purposes you can also change the reboot command to halt or whatever you'd like.
  4. lupinnktp

    lupinnktp Addicted to LI Member

    thx a bunch, man. i haven't tried it yet, but will do, and report back. this might very well stop my roommate from plugging my com out when i'm away, hehe.
  5. lupinnktp

    lupinnktp Addicted to LI Member

    i tried it and i have a problem. it script works. i changed the value to 900 (to tell it to ping every 15 minutes). however everytime the vlan1 up runs, there is a brief lag period of abt 1-2 seconds which is quite annoying. i'm wondering if the if-then argument could be reversed such that nothing happens unless the ping return is bad (instead of an vlan1 "renew" every interval)
  6. bogderpirat

    bogderpirat Network Guru Member

    try "service wan start" and "service wan stop" instead of ifconfig vlan1 up/down. you might also want to check before either commands whether the connection is currently up or down, so that when the connection is established, you don't make him try to re-dialin. you could accomplish this by checking whether `pidof pppoecd` is >0, that being a pppoe-connection.
  7. kardzzz

    kardzzz Addicted to LI Member

    not tested,,,,give this a try by inserting into your custom schedule; It probably only works if you enable QOS.
    Script checks if IP (change to your IP) is online, if yes the QOS rates are set to your limits, else we drop it to 5 in/out to kill the line. Does a service restart so its pretty instant.

    #Checks if IP is active and do some task
    if [ -n "`ping -c 1 -w 1`" ];
    nvram set qos_obw=465
    nvram set qos_ibw=10240
    service qos restart
    nvram set qos_obw=5
    nvram set qos_ibw=5
    service qos restart

Share This Page