Wake-On-Lan Shell Script for DD-WRT [Updated 08/2012]
I needed a way to wake up my server when I was away. I don’t like to keep it running all day, so Wake-On-Lan was the solution for me. I run DD-WRT as the Firmware on my router, so I knew that I could write some kind of script for it to do that for me. Since DD-WRT already includes a Wake-On-Lan binary, I searched the DD-WRT site, and found a script that is supposed to do WOL, but it didnt really work, so I borrowed the Idea, and created my own:
Update [08/2012]:
DD-WRT now requires you to add “#!/bin/sh” to the beginning of every script, so I updated the Script Accordingly!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#!/bin/sh #Wake-On-Lan Script for DD-WRT #by Pinchii - Feb, 2011 #http://pinchii.com/home/2011/02/wake-on-lan-shell-script-for-dd-wrt/ HOSTNAME=$1 WOL=/usr/sbin/wol HOSTS=/tmp/dnsmasq.conf ETH=br0 #Check if the user provided a host name to the script #otherwise exit with an error if [ -z "$HOSTNAME" ]; then echo Missing Parameter echo ----------------- echo "You must specify a hostname. Usage: $0 <hostname>" exit 1 fi #Now Find The Broadcast Address of the current configuration BCAST=`ifconfig $ETH | awk '/Bcast/ {split ($3,A,":"); print A[2]}'` if [ -z "$BCAST" ]; then echo Unable to Determine Broadcast Address for Interface $ETH fi #Since we have the Broadcast Address, lets try to find the Server/Host and Wake #it up SERVER=`grep ",$HOSTNAME," $HOSTS` if [ -n "$SERVER" ]; then MAC=`echo $SERVER | awk -F[,=] '{print $2}'` echo Sendind Wakeup to Network on $BCAST to $HOSTNAME at Address $MAC $WOL -i $BCAST $MAC else echo Error echo ------------------- echo "Unable to find \"$HOSTNAME\" in hosts file $HOSTS." exit 1 fi |
Once you get the script into your router, to use it, all you have to do is type “./wol.sh <servername> and the script will handle the rest
This script looks at your dnsmasq.conf file, so if you have a DHCP reservation for your server like I do, it should be included in this file as a “static” ip adress, along with the MAC address, which is what you really need for WOL to work
Thanks so much, I put this in the Web Gui, saved as a custom script so it will still be there after reboot. Works like a charm. Love the fact that I can specify the host name. Before I had a script that could only wake up a specific computer/mac combo.
Im glad…
I dumped my script into my jffs folder, then on startup I do an symbolic link to the root folder. Just so I can be lazy and not have to take any extra steps 🙂
Hi, first excuse my english im mexican, i have been trying to set up the wol on my linksys e3000 with tomato and fail, its been 3 weeks and nothing seems to work… i have no knowledge on telnet ssh or routers in general, can you please help me set the wol up with some detailed instructions¿ Thanks!
Sure, just send me your email via the Contact Me page, and ill be happy to help.
Even though I dont have Tomato installed, it should be pretty easy I think.
In Spanish:
Claro, mandame to e-mail por la pagina “Contact Me” y tratare de ayudarte, aunque no tengo Tomato instalado, tratare de ayudarte
linksys router address…
[…]Pinchii's Blog » Wake-On-Lan Shell Script for DD-WRT[…]…