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

WOL Script

Discussion in 'Tomato Firmware' started by sknnyftn, Feb 9, 2009.

  1. sknnyftn

    sknnyftn Addicted to LI Member

    I was wondering if it is possible to run a script that would send a wol packet to my xp machine whenever my xbox 360 turns on and obtains an ip address. I use the xbox almost exclusively for streaming media from tversity and playon and would like to be able to put the pc in standby when not in use. I appreciate any help I can get.
     
  2. quinezhu

    quinezhu Addicted to LI Member

    when your xbox 360 turns on and obtains an ip address then the router send a wol packet to your xp machine automatically?
     
  3. sknnyftn

    sknnyftn Addicted to LI Member

    Yes, I'd like it to be automatic is possible.
     
  4. bigclaw

    bigclaw Network Guru Member

    Some random idea: does the xbox 360 accept pings? You can write a custom script that pings the xbox 360 every 5 seconds and issues the WOL command once it gets a response.
     
  5. scolbeck

    scolbeck LI Guru Member

    I do a similar thing for Tomato to turn on my MythTV backend when the frontend machine is turned on.

    I assigned my frontend machine a static DHCP address of 192.168.1.5. When Tomato assigns it the IP address, within a minute, the following script will turn on the backend via the ether-wake command.

    I have the following in Administration->Scripts->WAS Up:

    Code:
    # Monitor the log for DHCP/CIFS/HTTP events to wake the server via WOL
    if [ ! -x /tmp/wolLogWatch.sh ] ; then
    touch /tmp/mythtv.tmp
    cat > /tmp/wolLogWatch.sh <<EOF
    #!/bin/sh
    
    MYTHTV="DHCPREQUEST\\(br0\\) 192.168.1.5"
    MAC=00:1d:7d:05:c4:60
    
    # Turn on the MythTV backend via WOL when the frontend turns on
    LAST_MYTHTV=\`cat /tmp/mythtv.tmp\`
    MYTHTV_LOG=\`grep "\$MYTHTV" /var/log/messages | tail -1 | awk '{print \$1" "\$2" "\$3}'\`
    if [ "\$MYTHTV_LOG" != "" -a "\$MYTHTV_LOG" != "\$LAST_MYTHTV" ]; then
       /usr/bin/ether-wake \$MAC
       echo \$MYTHTV_LOG > /tmp/mythtv.tmp
       exit 0
    fi
    
    EOF
    chmod +x /tmp/wolLogWatch.sh
    fi
    
    # Execute via cron every minute
    cru a wolLogWatch "* * * * * /tmp/wolLogWatch.sh"
     
  6. sknnyftn

    sknnyftn Addicted to LI Member

    scolbeck,

    That sounds like exactly what I have been looking to do. Could I just change the ip and mac addresses and get that script to work for my needs, or will it take some other changes as well?
     
  7. scolbeck

    scolbeck LI Guru Member

    Yes, with only the IP and MAC address change, it should work as is for you. Also note that Tomato will only run the script when the WAN first comes up. So even though the script is saved in Tomato, since the WAN is already up, it won't automatically run. You can either paste the entire script in Tomato's shell command line or reboot your router to make the script run.
     
  8. sknnyftn

    sknnyftn Addicted to LI Member

    I changed the ip address to match my static dhcp for the xbox and the mac address to match the computers. After rebooting the router I end up with the following logs and no response on the computer. Any ideas what I have messed up?


    Feb 10 18:36:47 deena-wsncvkn8a daemon.info dnsmasq[117]: DHCPDISCOVER(br0) 00:17:fa:29:e8:c9
    Feb 10 18:36:47 deena-wsncvkn8a daemon.info dnsmasq[117]: DHCPOFFER(br0) 192.168.1.121 00:17:fa:29:e8:c9
    Feb 10 18:36:47 deena-wsncvkn8a daemon.info dnsmasq[117]: DHCPDISCOVER(br0) 00:17:fa:29:e8:c9
    Feb 10 18:36:47 deena-wsncvkn8a daemon.info dnsmasq[117]: DHCPOFFER(br0) 192.168.1.121 00:17:fa:29:e8:c9
    Feb 10 18:36:47 deena-wsncvkn8a daemon.info dnsmasq[117]: DHCPREQUEST(br0) 192.168.1.121 00:17:fa:29:e8:c9
    Feb 10 18:36:47 deena-wsncvkn8a daemon.info dnsmasq[117]: DHCPACK(br0) 192.168.1.121 00:17:fa:29:e8:c9
    Feb 10 18:37:01 deena-wsncvkn8a cron.err crond[99]: USER root pid 466 cmd /tmp/wolLogWatch.sh
    Feb 10 18:38:01 deena-wsncvkn8a cron.err crond[99]: USER root pid 478 cmd /tmp/wolLogWatch.sh
    Feb 10 18:39:01 deena-wsncvkn8a cron.err crond[99]: USER root pid 489 cmd /tmp/wolLogWatch.sh
     
  9. scolbeck

    scolbeck LI Guru Member

    I apologize for this. I think the problem was the script I gave you. I have multiple frontend machines that could turn on my backend. I modified the script I gave you for use with one machine but screwed up. The simplest fix for you is to change the 'grep' to a 'egrep'.
     
  10. sknnyftn

    sknnyftn Addicted to LI Member

    Thanks for all your help. I made the change and it worked just fine. Now I have to try and figure out why the pc will only stay awake for 5 minutes afterwards. Even though I am streaming videos from the pc, it goes back into standby after only five minutes. So far it looks like I will need to figure out a way to monitor network trafffic from the pc to prevent standby.
     
  11. sknnyftn

    sknnyftn Addicted to LI Member

    I found a progam that runs in the system tray and monitors the ports being used by tversity and playon and denies the windows attempt to go back into standby so quickly. So now I have accomplished everything I was trying to do. Thanks for all your help scolbeck.
     
  12. quinezhu

    quinezhu Addicted to LI Member

    Maybe you need to enter the properties of your network card and check "Allow this device to bring the computer out of standby", and then uncheck "Only allow management stations to bring the computer out of standby".

    Or maybe you need to disable the auto system standby in the power options.
     
  13. aquamars

    aquamars Guest

    Hi everyone!
    I'm new to Tomato, even more to scripts...
    Would it be possible to modify this script in order to the WOL part to execute when there is an entering HTTPS or SSH connection?
    Even better, maybe a request on 5900 port? To avoid me to first WOL and then VNC / AFP into my computer...

    Thanks from Argentina!
    Martin
     

Share This Page