Plex, DDWRT, & Wake-On-Lan Almost working

I have a dedicated plex media server and would like it to wake up when using plex.
I am using the method of the dd-wrt router to wake up the server.
Took me a while but finally got it to work, although still not completely.

Here’s the script I use. (deleted mac for privacy)

INTERVAL=1
PINGTIME=1
OLD=""
PORT=32400
WOLPORT=9
TARGET=192.168.1.64
BROADCAST=192.168.1.255
MAC=xx:xx:xx:xx:xx:xx
WOL=/usr/sbin/wol
LOGFILE="/tmp/www/wol.html"

echo “<meta http-equiv=“refresh” content=“10”>” > $LOGFILE
echo “AUTO WOL Script started at” date
” >> $LOGFILE

while sleep $INTERVAL;do
NEW=dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print }' | tail -1
SRC=dmesg | awk -F'[=| ]' '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/ {print $7}' | tail -1
LINE=dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ && /DPT='"$PORT"'/'

if [ “$NEW” != “” -a “$NEW” != “$OLD” ]; then
if ping -qw $PINGTIME $TARGET >/dev/null; then
echo “NOWAKE $TARGET was accessed by $SRC and is already alive at” date
”>> $LOGFILE
else
echo “WAKE $SRC causes wake on lan at” date
”>> $LOGFILE
$WOL -i $BROADCAST -p $WOLPORT $MAC >> $LOGFILE
echo “
” >> $LOGFILE
sleep 1
fi
OLD=$NEW
fi
done

This is put in startup with the web interface
I see in some instructions this part, but it’s not clear to me. What do the first 2 lines mean?

#!/bin/sh
#Enable JFFS2 and place script in /jffs/ then run on startup in web interface.
#You can check the log from http://192.168.1.1/user/wol.html

Now to the problem, the server wakes when I access it from outside my own network.
But when the servers is awake, the routers keeps sending the wake command.
I see this line in the script 'echo “NOWAKE $TARGET was accessed by $SRC and is already alive at” date
”>> $LOGFILE ’ which makes me believe that when the server is online I should get a message in the log, and the wake command is not send. However I never get this message, looks like the dd-wrt doesn’t see the server a being on, this also explains why it keeps sending the wake command every couple of seconds.

The server doesn’t wake when accessed from local lan. This I just don’t understand…

Anyone that can help me finetune things??

Any luck getting this working? I’m looking to implement the same WOL capability with my Plex server and DD-WRT router.

Hey Guys,
I am also trying to implement this on my machine.
I have a DDWRT router. I can wake my box using the router web interface already (box is ready)
I am also trying to use this script, but there is something off on the logs retrieval.
I can’t find a single call to port 32400 using dmesg on the router.
The idea is good, just need some tweaking.
Does any of you managed to get this going?
Can a developer tell us what sould we be looking for on the router logs to wake our boxes?

Thanks.