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

Issue WOL when IP active (Tomato)

Discussion in 'Tomato Firmware' started by kapkap, Sep 27, 2010.

  1. kapkap

    kapkap Addicted to LI Member

    Hello all,

    I was wondering if someone can help out to get a script to run when a IP is active on the router?

    I use the scheduler in Tomato to run a WOL script ("sh /tmp/home/root/wakeup_server.sh") that wakes up my server normally. I'd like to have this script run when my media player (XBMC) is turned on (it has a static IP). Should be possible, right?
  2. rhester72

    rhester72 Network Guru Member

    If the output of this:

    ping -c1 <IP_of_XBMC> | grep -c " 0% packet loss"

    is a 1, the media player is active, otherwise, it's not.

  3. kapkap

    kapkap Addicted to LI Member

    Thanks rhester72

    Would a script like below do the trick?
    while [ 1 ]
    	# Send WOL if ping not equal to zero.
    	if [ $(ping -c1 192.168.1.xxx | grep -c " 0% packet loss") -ne 0 ]
    		sh /tmp/home/root/wakeup_server.sh
    	# Wait
    	sleep 15
    And start it with this...
    sh /tmp/home/root/ping_ip.sh &
    Sorry if this is sloppy, I'm still learning Linux. This would need to be created each time the router boots (Scheduler INIT tab I guess). How would I create this?
  4. rhester72

    rhester72 Network Guru Member

    Right on all counts.

    A wrapper construct, paste-ready into the Init page (slightly simplified to save on precious nvram):

    echo '#!/bin/sh
    if [ ! -f /tmp/ping_ip.chk ];then
    touch /tmp/ping_ip.chk
    while true;do
    [ $(ping -c1 192.168.1.xxx|grep -c " 0% packet loss") -gt 0 ] && sh /tmp/home/root/wakeup_server.sh
    sleep 15
    sh /tmp/ping_ip.sh &
    You should be able to use the same strategy to create wakeup_server.sh by using echo statements with redirects to build it from within the ping_ip script - or even just inline it. Let me know if you need help.

  5. kapkap

    kapkap Addicted to LI Member

    Tested this last night and it worked great. I didn't know you could write it that way. I also wasn't sure how to write the whole script out in one echo statement :)

    Thanks a bunch.

Share This Page