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/") 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 | grep -c " 0% packet loss") -ne 0 ]
    		sh /tmp/home/root/
    	# Wait
    	sleep 15
    And start it with this...
    sh /tmp/home/root/ &
    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|grep -c " 0% packet loss") -gt 0 ] && sh /tmp/home/root/
    sleep 15
    sh /tmp/ &
    You should be able to use the same strategy to create 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.
  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