Zx4161, you were right. That was holding my box awake. Now it is sleeping after the time I specified
That Dshutdown seems a real nice tool ! I will play with it latter.
Sorry about the long delay on the feedback.
But I did some more improvement on this. I got to stop !
I ran this on my router for quite a few days. The performance was nice !
Not much memory nor CPU for it.
The only hiccup was on the log file. After a day or so of Plex use, the log file had so many lines that the 10 seconds refresh did not let the page to be loaded to the end by that time.
That was my latest improvement. There is a parameter for the log file size. After that limit is reached, it will empty the file, keep the last 10 calls that woke the server, show a message about the cleanup and continue the log.
I am sharing 2 scripts. One with the entire log process commented and another with the log process uncommented.
You’re awesome joaoptc! Now this script works on routers that don’t have a built in switch correct? Would someone need to set up their iptable? Would you need to setup a vlan?
Thanks buddy
No need to set up anything ! No need to enable login, firewall nor a thing.
Just start your server! As the server start on local port 32400, there is need to change anything.
The script will search for any connection to the configured server on the configured port. In the example I posted 192.168.1.2:32400
This is perfect however not sure exactly how this works. I copy and pasted this in udner
administrator commands…I then save startup…How do I know it has been saved etc…
Plex coders please enable WOL packets in your application it just make to much sense!!!
Wake on lan magic packets are not necessary. Just allow your computer to wake on any network traffic by unticking wake on magic packet. This works fine for me and my computer sleeps and wakes as required.
works for me also when I use my app on my phone. In my opoin this should be a feature on the Plex app.
People that run plex are for the most part home users that don’t need a PC or Server on all the time. I would agree 100% enterprise network Server should never never never go off.
I haven’t be able to get this script to work so far!!!
@jimf22 said:
This is perfect however not sure exactly how this works. I copy and pasted this in udner
administrator commands…I then save startup…How do I know it has been saved etc…
Plex coders please enable WOL packets in your application it just make to much sense!!!
It should show up in a grey box underneath the commands box if you are running ddwrt. Also, don’t forget to reboot the router so the script starts. Thanks to @joaoptc the script now works on routers that don’t have a lan switch.
Hey Jimf22,
first thing would be to test if your WOL is configured correctly. You can try that using the router interface. There is a WOL tab you can wake you PC.
After saving and rebooting the router, you can check the logs at http://192.168.1.1/user/wol.html
In there you will monitor the activity of the network.
Give me more details on what is happening and we will figure this out.
I am skimming through this thread. It is not clear if this can be extended to wake-up Windows 10 (64bit Pro) over LAN not only to access Plex server but also to wake up a sFTP (secure FTP) server that I’d like to be able to access remotely - that is in both case even when PC is in sleep/standby mode.
The script is ment to wake the server when you access plex remotely or through lan. If you want to take the time I’m sure you can modify it to wake the computer when you access your ftp server
So I have read through the thread and I am not able to get this to wake my server through lan or remote. I have followed your steps very closely and have went as far as to start completely over form scratch with no resolve.
Here are my steps taken
running DDWRT on TP link Archer 7 v2 - working great
I have a static Ip set and port forwarding set to 32400. Image attached
set manual port to 32400 on PMS. Shows its fully accessible.
I have copied the script from the docx file into the commands tab and saved as startup. I changed to my static IP and PMS servers MAC
Rebooted everything so many times Ive lost count along with several 30/30/30 resets
got three checked boxes on my lan adapter in device manager
Set my power settings to blanaced
I have dshutdown installed and configured as instructed
I have setup the scheduled task
Im sure that I am missing something. I put my computer to sleep manually by going to the power button in the start menu and then try to test waking the computer on a laptop connected to the router wifi and my iPhone connected to cell data. Neither have woke the server.
I am trying to make this work but it’s giving me a hard time. My dd-wrt router is my secondary router thanks to my isp router. Anyone ideas to make that work with this (or an edited) script?
Hey Guys !
As a start, I would always start in parts: First, download a WOL software to your phone, or use the interface on DDWRT to configure and make sure you understand how your computer WOL works (there are differences) Once that is done, jump to the scripts. I would recommend mine, as the one Zx4161 shared didn’t work for me.
Where do I find your script? I know my WOL works with teamviewer. Do I need to have to use a WOL app separate from my plex app to wake the computer? My thinking here was that once I opened my plea app and it tried to connect it would wake my computer. Is this not the case?
So bare with my noob questions. Im not certain which script I should use as far as with or without log. Whats the difference? Also, do I replace the script as a startup command?
I took everything that’s been written on this forum and posted it on this discussion https://forums.plex.tv/discussion/259783/wake-on-lan-wol#latest
that way you can find it all on one page. Kudos to joaoptc for that other scritp for routers with non switch lan ports.
Enjoy, any questions feel free to ask
I have been working hard to get this script to work. I admit that I am running Plex on a Mac but the findings I have done might also be useful for non-Mac-users. I had several issues to fix before the script worked great, but now it is al running smoothly
First of all I’d like to say that setting up the router correctly is very important to prevent issues later while using the WOL script. I’ve had help setting up my DD-WRT router as a second router because I am bound to mu ISP router. Unfortunately the help I got was on a Dutch forum so not everybody will be able to follow this, for those who do: page 36/37 on the following site:
After setting up the router WOL worked, and using the script from jaoptc, it also worked when opening PLEX apps. The first two problems followed. 1) after a few minutes of sleep, the Plex apps didn’t trigger WOL anymore. Manual WOL still worked. 2) Opening the PLEX app on my LG WebOS 3 tv didn’t trigger WOL at all.
The problem seemed to be that the Mac address disappeared from the router ARP table. Long story short: the solution to this problem was to add another line to the script under Purgecount (see script at the bottom of the post).
While testing this solution another problem came up (don’t worry if this happens to you also, the green line works). The following problem was that the Mac woke up after a minute of sleep. It would then fall asleep after another minute and so forth.
While this seemed to be one problem, the sleep and wake where separate problems. Due to the fact that both of these problems need you to disable SIP (System Integrity Protection) I will explain the solutions of both here. The reason you need to disable SIP is to enable you to edit system files you normally can’t edit.
The first solution is for the sudden wakes of the Mac. I looked deeper in to the reason why the Mac waked by entering the following command in Terminal:
Step 1 is to disable SIP:
To disable SIP you start up the Mac in Recovery Mode. This is achieved by shutting down the Mac. When powering the Mac back on hold the CMD + R buttons until the Apple logo appears. From there go to Utilities > Terminal and enter the following
csrutil enable
Hit enter and when you see the confirmation restart the Mac and let the Mac boot normally.
After SIP is disabled and the Mac has restarted open Terminal and enter the following command:
Go to the line /usr/sbin/mDNSResponder and insert the following line:
<string>-NoMulticastAdvertisements</string>
After a reboot the wake reason RTC (Alarm) should be fixed.
The second problem which requires SIP to be disabled is the problem that the Mac fell asleep after a short wake period (< 1 minute). The core problem appeared to be that the Mac didn’t fully wake, but did a Dark Wake. The Mac checked if there was a valid reason for the WOL. If not, the Mac returned to the sleeping state. The solution is:
1 Open a Terminal window.
2 Type the following: cd /Library/Preferences/SystemConfiguration
and hit enter
3 Edit com.apple.Boot.plist by typing: sudo nano com.apple.Boot.plist
4 Move the insertion point down to the associated with the Kernel Flags
5 Type darkwake=0
6 Hit CTR + X, enter Y and hit Enter to save and quit the file.
7 Reboot the system.
After a reboot you need to enable SIP again.
This is done the same as disabling it, but by typing
csrutil enable
After these modifications my Mac sleeps and wakes perfectly.
In the process I found a lot of information about Sleep modes on the Mac and on Hibernation.
WOL also works when Hibernation is enabled. Since this is not a standard setting there is another command needed.
More info about Sleep vs Hibernate is on those two sites:
Beneath you can find my final DD-WRT script. The TARGET, BROADCAST and MAC sections need to be edited according to your setup.
Hope this helps some of you!!
Regards
Patrick
———————————————————————————————————————————
#!/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
INTERVAL=2
PINGTIME=1
OLD_TIME=""
PORT=32400
WOLPORT=9
TARGET=192.168.1.252
BROADCAST=192.168.1.255
MAC=XX:XX:XX:XX:XX
WOL=/usr/sbin/wol
LOGFILE="/tmp/www/wol.html"
# Never change LOGLINESTOSTORE to under 100. It will create pretty much a loop on the cleanup log procedure
LOGLINESTOSTORE=500
PURGECOUNT=0
# To Broad cast the WOL when Server is out of the ARP table.
arp -i br0 -s $TARGET $MAC
echo "<meta http-equiv=\"refresh\" content=\"10\">" > $LOGFILE
echo "["`date`"] AUTO WOL Script started. <br>" >> $LOGFILE
echo "For server: $TARGET:$PORT and MAC: $MAC on port $WOLPORT <br>" >> $LOGFILE
tcpdump -q -n -i any -p -P out -K -l -O -U 'dst host '$TARGET' and dst port '$PORT'' 2>/dev/null | while read NEW ; do
# Get the line in seconds, to minimize the number of processed commands.
NEW_TIME=`echo $NEW | awk -F'.' '{print $1}'`
if [ "$NEW_TIME" != "$OLD_TIME" ]; then
# Get the source IP for logging
SRC=`echo $NEW | awk -F'[.| ]' '{print $4"."$5"."$6"."$7}'`
# If box is alive (responding to ping)
if ping -qw $PINGTIME $TARGET >/dev/null; then
echo "[`date`] NOWAKE - $TARGET accessed by $SRC <br>">> $LOGFILE
#touch /dev/null
else
echo "[`date`] _WAKE_ - $TARGET accessed by $SRC <br>">> $LOGFILE
$WOL -i $BROADCAST -p $WOLPORT $MAC >> $LOGFILE
echo "<br>" >> $LOGFILE
fi
OLD_TIME=$NEW_TIME
# Cleanup log file procedure, keeping the header and the last 10 last WAKE log lines
if [ "`wc -l $LOGFILE | awk -F'[ ]' '{print $1}'`" -gt "$LOGLINESTOSTORE" ]; then
head -n 3 $LOGFILE > /tmp/www/wol.tmp
PURGECOUNT=$((PURGECOUNT+1))
echo "Log File purged $PURGECOUNT times, last one at $NEW_TIME <br> " >> /tmp/www/wol.tmp
grep _WAKE_ $LOGFILE | tail -n 10 >> /tmp/www/wol.tmp
mv /tmp/www/wol.tmp $LOGFILE
echo "<br>" >> $LOGFILE
fi
sleep $INTERVAL
fi
done