Auto Wake On LAN script for hosts

At the very least, users should consider putting the LOGFILE on /tmp/ rather than on flash. OpenWrt also does not serve HTML pages in the same way as DD-WRT.

Note also problems with rebooting a router running this script described at

Hi guys, I found on this useful script for wake up a host by request.
I use it to wake up my NAS if my Kodi or PC want anything from it.


  • Firmware Version: OpenWrt Barrier Breaker 14.07 / LuCI Trunk (0.12+svn-r10530)
  • Kernel Version: 3.10.49
Required to change Variables Default value Description
optional INTERVAL 5 repeat the script every N second
not required OLD empty should be empty
optional PORT 80 it the port who looks the script
optional NUMP 3 the retries, before the script gave up
yes TARGET the wake up device
yes INTERFACE br-lan here you can type in a broadcast address or a interface, i like more interface
yes MAC 00:00:00:00:00:00 the target mac adress
not required WOL /usr/bin/etherwake the program and path for wol
optional LOGFILE “/www/wol/index.html” the log output folder, in this case for the url <ROUTER-IP>/wol/index.html
optional LOGPROG “logread” i will read the logs from LOGREAD, but you can also read from “dmesg” or something else

Install the required packages.

opkg update
opkg install etherwake

Saving the script.

cat << "EOF" > /bin/
#Enable JFFS2 and place script in /jffs/ then run on startup in web interface.
#You can check the log from
#set -xv
LOGPROG="logread" # default: dmesg
echo "<meta http-equiv=\"refresh\" content=\"10\">" > $LOGFILE
echo "AUTO WOL Script started at" `date` "<br>" >> $LOGFILE
wake_up () {
	NEW=`$LOGPROG | awk '/WOL_LOG/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print }' | tail -1`
	SRC=`$LOGPROG | awk -F'[=| ]' '/WOL_LOG/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print }' | tail -1`
	LINE=`$LOGPROG | awk '/WOL_LOG/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/'`
	if [ "$NEW" != "" -a "$NEW" != "$OLD" ]; then
		if ping -qc $NUMP $TARGET >/dev/null; then
			echo "NOWAKE $TARGET was accessed by $SRC and is already alive at" `date` "<br>">> $LOGFILE
			echo "WAKE $SRC causes wake on lan at" `date` "<br>">> $LOGFILE
			echo "<br>" >> $LOGFILE
			sleep 5
while sleep $INTERVAL; do
chmod +x /bin/

Pro Tip: Don't copy the code above as it causes a bunch of errors due to a stray CRLF character at the end of each line. Instead just download a copy of the file here, and save yourself a day of troubleshooting!

First autostart, if the script is ok.

Go to System → Startup → Local Startup and type in:


Enable debug output:

sh -x -v /bin/

Check the log file:

Go to Network → Firewall → Custom Rules and add this rule:

iptables -I FORWARD 1 -p tcp -d -m limit --limit 1/min -j LOG --log-prefix "WOL_LOG:  " --log-level 7
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2023/03/19 10:12
  • by ryanc