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.0k 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.
    • johnpozJ
      johnpoz LAYER 8 Global Moderator
      last edited by

      Yeah I love to tinker myself.. The thing I found with putting pcs to sleep - is they more often than not have issues coming out of it..  So just when I want to do something, the F'ing thing decides to have a fit about coming out of standby/hibernate..

      It normally not worth it..

      So you do not use thumbnails - shame that is one of the best features… Now its more like netflix and you can tell exactly where your at when you fastforward/rewind.  Did you take a look at all the other stuff it downs on scheduled tasks.. Optimize the database, metadata info, etc..

      Problem people have is they think oh my PC has 1000W power supply in it..  Doesn't mean its using anything close to that..  My PC sits idle at like 45 watts.. The 2 monitors are what use more juice..  So just took a look at my ups records.. Now keep in mind that I have quite a bit of stuff running off this ups.. My PC, my sg-4860, my sg300-28 switch.  4 different raspberry pi's... My 2 monitors, alexa dot, speakers... This is total usage not just idle.. So in the month of dec used 100Kwh.. At 16 cents per kwh your talking 16$  My PC is small portion of that..  The few bucks going to save putting my pc to sleep just not worth it.. If you want to tinker I would suggest you tinker towards what your currently using so you will understand if worth the time and effort to put your stuff in standby or buy more power friendly devices, etc.

      Killawatt meter great tool to have in your tool belt when looking to see how much juice your stuff is drawing now, when idle over X number of days, etc..

      This the one I have https://www.amazon.com/P3-P4400-Electricity-Usage-Monitor/dp/B00009MDBU

      And then the attached is from running business software for my cyberpower ups..

      energyuse.png
      energyuse.png_thumb

      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 24.11 | Lab VMs 2.8, 24.11

      1 Reply Last reply Reply Quote 0
      • GertjanG
        Gertjan
        last edited by

        @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
          yakboyslim
          last edited by

          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
            yakboyslim
            last edited by

            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
            • GertjanG
              Gertjan
              last edited by

              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
              • johnpozJ
                johnpoz LAYER 8 Global Moderator
                last edited by

                "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 24.11 | Lab VMs 2.8, 24.11

                1 Reply Last reply Reply Quote 0
                • Y
                  yakboyslim
                  last edited by

                  @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
                    yakboyslim
                    last edited by

                    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
                    • johnpozJ
                      johnpoz LAYER 8 Global Moderator
                      last edited by

                      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 24.11 | Lab VMs 2.8, 24.11

                      1 Reply Last reply Reply Quote 0
                      • Y
                        yakboyslim
                        last edited by

                        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
                        • johnpozJ
                          johnpoz LAYER 8 Global Moderator
                          last edited by

                          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 24.11 | Lab VMs 2.8, 24.11

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post
                          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.