• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

WOL automatically for PLEX. Need help with syntax.

Scheduled Pinned Locked Moved General pfSense Questions
19 Posts 3 Posters 3.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    Gertjan
    last edited by Jan 30, 2018, 10:35 PM

    @yakboyslim:

    ….
    It looks like I can use clog to make the log files readable by grep, ….

    CO2 or not, you have a scripting future  ;)

    No "help me" PM's please. Use the forum, the community will thank you.
    Edit : and where are the logs ??

    1 Reply Last reply Reply Quote 0
    • Y Offline
      yakboyslim
      last edited by Feb 1, 2018, 11:07 PM

      Well johnpoz, you convinced me. I set up Preview thumbnails. I had been putting it off because I didn't want to eat up my OS drive, but I used a symlink to put that stuff on a data drive and started it up.

      I also got a smartthings plug for a separate project and it will report power draw. I plugged my PC into that and as I suspected I am drawing about 160 W at idle. I draw 8.5 during sleep. Using those numbers and 10 hours of on time per day (which is probably a high estimate) I see that I can save $10 a month. That is not insignificant. I agree waking computers from sleep is occasionally troublesome, but for $10 a month I will try it.

      I know $120 a year almost makes it seem worth it to get a more efficient Plex server. But TBH my computer (Dell T-5500) was free (I have upgraded it, but most parts are original) and I can use it for Plex, game on it, and do movie editing etc super quick.

      Now to figure out this script…

      1 Reply Last reply Reply Quote 0
      • Y Offline
        yakboyslim
        last edited by Feb 2, 2018, 2:40 AM

        Here is my script now. I am still getting errors, but I think this is better. The clog | grep part works if I type it into the shell, but it doesn't run as a script.

        #!/bin/sh
        
        TARGET='xxx.xxx.xxx.xxx'
        MAC='xx:xx:xx:xx:xx:xx'
        
        INTERVAL=2
        NUMP=1
        
        OLD_LINE=clog /var/log/filter.log | grep "1497674444" | tail -1
        echo "$OLD_LINE"
        while sleep $INTERVAL
        do
            # Only care about new lines since the script last ran
            NEW_LINE=clog /var/log/filter.log | grep "1497674444" | tail -1
            if [ "$NEW_LINE" -ne "$OLD_LINE" ]
             then
                echo "NEW TRAFFIC"
                 RET=`ping -c $NUMP -W 1 $TARGET 2> /dev/null | awk '/packets received/ {print $4}'`
                 if [ "$RET" -ne "$NUMP" ]
                     then
                        # Guess it's sleeping. Send WoL.
                        echo "[`date -Iseconds`] WOL. Line was $NEW_LINE"  >> /var/log/wol
                        wol -i $TARGET $MAC
                        # Could sleep for 20 minutes I guess...I mean, there's no real reason to check again.
                        # Whatever...10 seconds is fine.
                        sleep 1200
                    fi
                fi
            fi
            OLD_LINE='clog /var/log/filter.log | grep "1497674444" | tail -1'
        done
        

        Here is the errors I get

        [2.4.2-RELEASE][root@pfSense.localdomain]/usr/local/etc/rc.d: sh WOLplex.sh
        : not found
        : not found
        : not found
        WOLplex.sh: /var/log/filter.log: Permission denied
        tail: illegal option -- -1
        
        WOLplex.sh: 31: Syntax error: "done" unexpected (expecting "then")
        
        

        Note I cannot execute WOLplex.sh, or ./WOLplex.sh. I bet this might be something simple about permissions, but unfortunately I skipped all the basics so I don't know what I'm missing.

        1 Reply Last reply Reply Quote 0
        • G Offline
          Gertjan
          last edited by Feb 2, 2018, 10:11 AM

          Try this :

          #!/bin/sh
          
          OLD_LINE=`clog /var/log/filter.log  | grep "1497674444" | tail -1`
          
          echo "$OLD_LINE"
          

          No "help me" PM's please. Use the forum, the community will thank you.
          Edit : and where are the logs ??

          1 Reply Last reply Reply Quote 0
          • J Offline
            johnpoz LAYER 8 Global Moderator
            last edited by Feb 2, 2018, 8:58 PM Feb 2, 2018, 8:52 PM

            "drawing about 160 W at idle"

            Wow that is running hot…  What is it exactly?  That was idle - the cpu not doing anything... Or were you mining crypto while it wasn't doing anything ;) hehehe

            What does it draw when actually doing something like transcoding a movie or 2?

            I did a quick google for T5500 and looks like this one is only drawing 93w idle?
            https://www.youtube.com/watch?v=7T4kMcpJVFc

            An intelligent man is sometimes forced to be drunk to spend time with his fools
            If you get confused: Listen to the Music Play
            Please don't Chat/PM me for help, unless mod related
            SG-4860 25.07 | Lab VMs 2.8, 25.07

            1 Reply Last reply Reply Quote 0
            • Y Offline
              yakboyslim
              last edited by Feb 2, 2018, 9:31 PM

              @johnpoz:

              "drawing about 160 W at idle"

              Wow that is running hot…  What is it exactly?  That was idle - the cpu not doing anything... Or were you mining crypto while it wasn't doing anything ;) hehehe

              What does it draw when actually doing something like transcoding a movie or 2?

              I did a quick google for T5500 and looks like this one is only drawing 93w idle?
              https://www.youtube.com/watch?v=7T4kMcpJVFc

              I looked at that video, he only has one processor. Mine has two.

              It was at idle. I think it's just older server hardware, not designed for idle efficiency.

              1 Reply Last reply Reply Quote 0
              • Y Offline
                yakboyslim
                last edited by Feb 2, 2018, 10:49 PM

                IT WORKS! (mostly…)

                Had to fix a lot of syntax (shellcheck.net helped a ton) and switch my line break style from windows to unix.

                #!/bin/sh
                TARGET='192.168.1.200'
                MAC='00:25:64:b8:33:85'
                INTERVAL=2
                NUMP=1
                OLD_LINE=$( clog /var/log/filter.log | grep "1497674444" | tail -1 )
                echo "Found this $OLD_LINE"
                while true
                do
                    # Only care about new lines since the script last ran
                    NEW_LINE=$( clog /var/log/filter.log | grep "1497674444" | tail -1 )
                    echo "New $NEW_LINE"
                    if [ "$NEW_LINE" != "$OLD_LINE" ]
                    then
                        echo "NEW TRAFFIC"
                        RET=$( ping -c 1 -W 1 192.168.1.200 | awk '/packets received/ {print $4}' )
                        if [ "$RET" -ne "$NUMP" ]
                        then
                            # Guess it's sleeping. Send WoL.
                            echo "WOL. Line was $NEW_LINE"  >> /var/log/wol
                            wol -i $TARGET $MAC
                            # Could sleep for 20 minutes I guess...I mean, there's no real reason to check again.
                            # Whatever...10 seconds is fine.
                            sleep 1200
                        fi
                    fi
                    echo "WAITING"
                    OLD_LINE=$( clog /var/log/filter.log | grep "1497674444" | tail -1 )
                    sleep $INTERVAL
                    echo "Old $OLD_LINE"
                done
                

                It works exactly like it should and wakes my computer no problems when accessed from WAN. Plex is ready in about 10 seconds. I plan to do some other automation (send WOL packet when the living room tv is turned on) so that we don't see that 10 second wait usually.

                When I try to access Plex from a device on my network it doesn't work, and double checking it does not appear I have a firewall rule that is tagging that traffic effectively.

                Any ideas? Right now I am looking for LAN traffic with a destination port of 32400-32450 which should capture all the ports. I get my LAN/WAN, source/destinations mixed up all the time though.

                1 Reply Last reply Reply Quote 0
                • J Offline
                  johnpoz LAYER 8 Global Moderator
                  last edited by Feb 3, 2018, 1:40 AM

                  why would you have a range of ports?  Do you have 50 plex servers?  Plex by default is port 32400, that is the only port it would be listening on.  You get what mixed up source/dest?

                  An intelligent man is sometimes forced to be drunk to spend time with his fools
                  If you get confused: Listen to the Music Play
                  Please don't Chat/PM me for help, unless mod related
                  SG-4860 25.07 | Lab VMs 2.8, 25.07

                  1 Reply Last reply Reply Quote 0
                  • Y Offline
                    yakboyslim
                    last edited by Feb 3, 2018, 2:11 AM

                    I just re-read my last post and it is not even close to clear, so I apologize for that.

                    I read somewhere that Plex used 32410-32414 or so for network discovery, I think. I figured I would just set a range and catch it all in there.

                    Traffic from a device on my local network to my Plex device would be going to that port as the destination on LAN correct?

                    If both these devices are on the same switch, they might be communicating directly there. Would the router see that traffic for the purposes of firewall rules? I would think so, especially if the Plex server is sleeping and the client has to "look" for it.

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      johnpoz LAYER 8 Global Moderator
                      last edited by Feb 3, 2018, 2:24 AM

                      If you have a network 192.168.x/24 lets call it - and your on 192.168.x.100 and plex is on 192.168.x.101 - no pfsense would never see that traffic.  The only thing plex might have to do is resolve plex.whatever.tld your using to 192.168.x.101

                      Yes if your .100 box is talking to your .101 plex server the dest would be 32400.. That is IT.. and the source would be whatever random high port your client is using for that session.. Something above 1024 and below 65515..

                      The only time pfsense would be involved in the traffic is if it was routing it.. so clients on 192.168.x/24 while your plex is on 192.168.y/24

                      An intelligent man is sometimes forced to be drunk to spend time with his fools
                      If you get confused: Listen to the Music Play
                      Please don't Chat/PM me for help, unless mod related
                      SG-4860 25.07 | Lab VMs 2.8, 25.07

                      1 Reply Last reply Reply Quote 0
                      19 out of 19
                      • First post
                        19/19
                        Last post
                      Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                        This community forum collects and processes your personal information.
                        consent.not_received