Hello everybody!
I am trying to have my plex media server automatically wake up from sleep when the router detects network traffic to the server.
I know it sounds kind of complex, but im almost there!
The solution requires a list of settings on the router config pages (logging enabled, set to level HIGH and log each accept, reject and dropped connection).
Then a shellscript thats running in the background (on the router) checks the syslogs to see if there is a match between the configured server ip and the configured port number.
If a match is found, the script pings the server and if it doesnt get a reply, it sends a wake on lan-packet to the server.
However, the script im trying to use only uses a single port number, while the plex media solution utilizes 6 different ports for initial contact.
And since those 6 ports differ from the default one, the server doesnt get a WOL-packet and the server remains unavailable.
So what i need is to modify the script to allow for more ports, so any of the ports directed to the server ip registers as a trigger.
I have many talents, but programming, shellscripts and similar are not one of them..
quite the opposite in fact, i have tremedous difficulties understanding it..
So i write here, hoping that someone might have the skills and time to make this change for me.
Im pretty sure im not the only one trying to get this feature enabled, so its not merely for me personally.
In any way, the ports that plex needs are as follows:
1900; DLNA
32400; default port
32410, 32412, 32413, 32414; ports for GDM network discovery
The script below is not written by me, its something i found in one of the tutorials covering the topic.
But these tutorials all expect one thing, that the default port is the only one used for initial contact, witch is incorrect.
Code:
#!/bin/sh
#Enable JFFS2 and place script in /jffs/ then run on startup in web interface.
#You can check the log from 192.168.1.1/user/wol.html
INTERVAL=1
PINGTIME=1
OLD=""
PORT=32400
WOLPORT=9
TARGET=192.168.1.25
BROADCAST=192.168.1.255
MAC=(Correct, deleted for privacy)
WOL=/usr/sbin/wol
LOGFILE="/tmp/www/wol.html"
echo "<meta http-equiv=\"refresh\" content=\"10\">" > $LOGFILE
echo "["`date`"] AUTO WOL Script started. <br>" >> $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` "<br>">> $LOGFILE
else
echo "WAKE $SRC causes wake on lan at" `date` "<br>">> $LOGFILE
$WOL -i $BROADCAST -p $WOLPORT $MAC >> $LOGFILE
echo "<br>" >> $LOGFILE
sleep 1
fi
OLD=$NEW
fi
done