LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-12-2017, 02:19 AM   #1
Alphonse
LQ Newbie
 
Registered: May 2017
Posts: 6

Rep: Reputation: Disabled
Question Script help needed! DD-WRT, Plex Media Server, traffic detect with WOL


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
 
Old 05-12-2017, 07:57 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
This link shows you can use awk to search for multiple values. It gives example:

Code:
awk '/Jun/ || /July/ || /Aug/' <(ls -lrh)
Based on that rather than having the single PORT= you could do multiple (e.g. PORT1=, PORT2= etc...) then within your awk line where you currently reference $PORT you could use the above search to do '/$PORT1/ || /$PORT2/ || etc...'
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Review Plex Media Server For Linux, Sync Media Across All Of Your Devices LXer Syndicated Linux News 0 02-29-2016 12:51 PM
Allow Plex Media Server traffic to bypass VPN connection English_Man Linux - Networking 3 01-02-2016 10:49 PM
[SOLVED] how to install plex media server on slackware 64 kaneh Slackware 2 09-15-2013 06:17 AM
Plex Media Server on Slackware64 Gee Man Slackware 1 10-01-2012 06:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration