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

(Script) Automatically boot your PC when coming home...

Discussion in 'Tomato Firmware' started by philess, Jan 25, 2013.

  1. philess

    philess Networkin' Nut Member

    Hi everyone,

    just thought i would share this very simple script, might be useful/fun for some of you.
    The idea is that you have a WLAN-connected smartphone with a static IP assigned to it in your home-network.
    Once you come home, it starts replying to ping and then your PC will get booted thru Wake-on-LAN.

    Requirements:
    • ether-wake installed on your Tomato-Router (should be default on all builds by now)
    • PC must be able to wake up by Wake-on-LAN
    • Smartphone with static or dhcp-static IP on your WLAN
    Set PHONE to your phone´s IP address, and set COMPUTER to your computer´s MAC address.
    (IP address can be used too, but i figure somehow MAC might be more reliable…)

    Note: You should not set the sleep interval too short ("while sleep 15"), this script will be run
    all the time in the background on your router, no need to ping every second. 15+ should be enough.

    Save the script somewhere like /opt/wakeup.sh and under "Administration/Scripts/WAN Up" enter:
    sh /opt/wakeup.sh
    To get it started, execute the above command once under "Tools/System".

    I advice you to test it before saving it permanently to be executed all the time:
    Execute it manually, turn your PC off. Then switch WLAN off on your phone. Put it back on
    after a little while and your PC should boot up. If all is well, add it as a WAN UP Script.

    If for some reason you want to stop it later on, you need to log in through SSH, do "top", look at
    the PID of the process running the script ("wakeup.sh"), CTRL+C do exit top, and then do "kill -9 <PID>".

    Code:
    #!/bin/sh
    PHONE="192.168.1.50"
    COMPUTER="00:00:36:44:97:E1"
     
    while sleep 15; do
    RESULT=`ping -c 1 $PHONE 2> /dev/null | awk '/packets received/ {print $4}'`
      if [ $RESULT -eq 1 ] ; then
            ether-wake $COMPUTER
      fi
    done
    Obviously this can easily be modified to wake up multiple PC´s, or do other stuff
    when you´re coming home. Or do the reverse: Shutdown your PC when you´re leaving…

    Please note, i am aware that this is a) nothing fancy and b) probably very ugly/bad code.
    I just found some WLAN-keepalive script (sorry cant find link anymore) and changed it.
     

Share This Page