Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question auto WOL when plex server is unavailable (scripting help needed!!)


    Hello all!

    Im trying to configure a DD-WRT router to detect traffic to my media server, and when detected, pings the server and if no reply, send a Wake On Lan magic package.


    Thereīs a couple of different tutorials that tries to solve this, but they are all not working for me..
    That "last step" always fails, since the script doesnt check for all neccisary port numbers, but only the default one.

    So i write here, hoping that a linux guru could help me modify the script, to allow more than one port

    the ports i need are 32400(default), 32410, 32412, 32413, 32414(port range for GDM network discovery) and 1900(DLNA).

    I know nothing of script (exept the very basic of apple-script from like 1990:ies) but i imagine that one could add the other ports as triggers, but i havent got a clue regarding how to make it so..

    But i figure that the current script boils down to "IF=correctIP && correctPORT, THEN=yadayada", but i think i would need something like:
    "IF=correctIP && (PORT1 or PORT2 or PORT3 (and so on))"..
    And just to clarify that last bit, the server ip is never-changing, but i need a WOL-trigger for any port number along with the specific server IP (local static ip)


    I know, its kind of rude of me asking someone else to do it for me, but ive been googling for days now and im still no closer to understand all these odd symbols and text-formatting in a shellscript..

    wolscript.txt

    ..and sorry for posting the script as attatchment, i would much rather included the script in code brackets along with my text, but unfortunately there are a number of text-lines in the script that the forum software interprets as URL and blocks me from posting...

  2. #2
    Quote Originally Posted by liggistUR View Post
    I know, its kind of rude of me asking someone else to do it for me, but ive been googling for days now and im still no closer to understand all these odd symbols and text-formatting in a shellscript..
    yes, it is rude.
    and i don't think anyone's going to do it for you, just like that.
    show some effort.
    get going with some basic shell scripting (bash i presume?) tutorials.

    i cannot see the attachment; many users of this forum have had problems with attachments. if you can't figure out how to circumvent the URL posting restriction, use a pastebin.
    I am not a "Linux Guru"! Get off me! The Forum software won't let me change it!
    How to ask smart questions | Don't be a Help Vampire
    You can post a link by removing "http://www." from it.

  3. #3
    Quote Originally Posted by nihili View Post

    i cannot see the attachment; many users of this forum have had problems with attachments. if you can't figure out how to circumvent the URL posting restriction, use a pastebin.

    Since i cannot post a URL, how exactly would i post a pastebin?
    im sorry for being stupid here, but i fail to see how that would be done...


    Iīll try posting the script again, hoping it still makes sense after neutering the URLīs..
    Code:
    #!/bin/sh
    #Enable JFFS2 and place script in /jffs/ then run on startup in web interface.
    #You can check the log from "router"/user/wol.html
    
    INTERVAL=1
    PINGTIME=1
    OLD=""
    PORT=32400
    WOLPORT=9
    TARGET=192.168.i.25 	# replace i with 1
    BROADCAST=192.168.i.255 # replace i with 1
    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

  4. $spacer_open
    $spacer_close
  5. #4
    Quote Originally Posted by liggistUR View Post
    i think i would need something like:
    "IF=correctIP && (PORT1 or PORT2 or PORT3 (and so on))"..
    your script doesn't seem to be doing anything of the kind.
    therte's just one PORT.
    if i were you, i'd replace the PORT variable with a port array:
    Code:
    ports=( 32400 32410 32412 32413 32414 1900 )
    and enclose the whole bit that greps the port from dmesg and "does things" in a for-do loop:
    Code:
    for (( i=0 ; i < ${#ports[@]}; i++ )); do
    etc....
    done
    random tutorial: The Ultimate Bash Array Tutorial with 15 Examples - Bash - Snipplr Social Snippet Repository
    I am not a "Linux Guru"! Get off me! The Forum software won't let me change it!
    How to ask smart questions | Don't be a Help Vampire
    You can post a link by removing "http://www." from it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •