Announcement

Collapse
No announcement yet.

Fun with server messages. My server let's me know if there's anything to update.

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Fun with server messages. My server let's me know if there's anything to update.

    I have a daily habit of logging into my headless server via ssh and running "apt update" and "apt list --upgradable" to see what needs to be updated. I don't like the idea that my server will auto-update and possibly break without me knowing what caused it. I've also decided to automate more of my daily tasks, and this was the next one (my server already checks for and updates my media server automatically).
    1. I installed openssh-server to my desktop, locked it down to only accepting incoming traffic from my server, changed the port from the default 22 as is my habit.
    2. Then, to make scripting easier, I created secure keys on the server and transmitted it to my desktop, and configured ssh client on the server to use the correct port and hostname for messages. Now I don't need a user password or hostname to send messages to my desktop.
    3. Next, I wrote a bash script that runs the two apt commands and put in the the root folder. The script sends the output of "apt list --upgradable" to my desktop using notify-send.
    4. Finally, I added a cron job to root crontab to run the script everyday at 8:30am


    Now, I should see this every morning:Click image for larger version

Name:	Screenshot_20170405_114548.png
Views:	1
Size:	10.2 KB
ID:	649184

    Cool!

    In case anyone wants to see it, here's the notify command:

    ssh office 'DISPLAY=:0 notify-send "Server has these packages to update:" "`apt list --upgradable`"'

    Please Read Me

    #2
    Update: Added the "package-install" icon and zero timeout to the message.

    Please Read Me

    Comment


      #3
      now that is cool ,,,,,,and just what you would think should happen in a case like yours (multi work station house and some headless servers) "have the server tell a work station that it has updates",,,,AND you say the notification lists the upgrades and provides a "OK go ahead and install them" button?

      your the man

      VINNY
      i7 4core HT 8MB L3 2.9GHz
      16GB RAM
      Nvidia GTX 860M 4GB RAM 1152 cuda cores

      Comment


        #4
        Thats cool. I may have to do something like that as well. Constantly checking my server for updates is a headache...

        Comment


          #5
          Originally posted by vinnywright View Post
          ...a "OK go ahead and install them" button? VINNY
          That's next on the list!

          Please Read Me

          Comment


            #6
            OK Update on this : it doesn't work the way I want. When I tested it last night, there were no upgradable packages so I assumed it was working. What I found out was it was running "apt list --upgradable" on my desktop and not the server. So it was notifying me that the desktop had upgrades, not the server. The issue is sending multi-line text over ssh using notify send. Nothing I read said it would work - or no one has figured it out yet.

            I fiddled with this a bit and finally landed on this idea:

            The script on the server now makes a text file of the updates the server needs.
            I use rcp to copy the list to a hidden file on the desktop.
            Then issue a notify-send command to the desktop to display the contents of the file.
            Since I wanted a list of packages, but not the versions and other stuff, I used sed to trim the output.

            This seems to work. Only thing now is for some reason, if I manually run the script on the server, I get an error on the sed command because the delimiter in the output I cut the lines at is a / which sed uses for it's syntax, so I escaped it with a \ but it still generates an error. However, as the error is on the server side and the output on the desktop side works - I may leave it.

            BUT, if any of you script geniuses have a better solution, I'm all ears.

            Here's the script on the server side:
            Code:
            #apt update >/dev/null 2>&1#apt list --upgradable > upgrade.list
            rcp upgrade.list  office:.serverupgrade.list
            ssh office 'DISPLAY=:0 notify-send -i package-install -t 0 "Needed server updates:" "`sed 's/\/.*//' .serverupgrade.list`"'

            Please Read Me

            Comment


              #7
              Spoke too soon again : the error prevents the message from arriving.

              Weird as the same exact command works on the desktop, but not through ssh...

              Please Read Me

              Comment


                #8
                Ok, reversing the quotes - double vs. single - seems to work.

                Code:
                apt update >/dev/null 2>&1
                apt list --upgradable > upgrade.list
                rcp upgrade.list  office:.serverupgrade.list
                ssh office "DISPLAY=:0 notify-send -i package-install -t 0 'Needed server updates:' '`sed 's/\/.*//' /root/upgrade.list`'"
                We'll see at 8:30am tomorrow...Click image for larger version

Name:	Screenshot_20170406_204453.png
Views:	1
Size:	46.8 KB
ID:	643493

                Please Read Me

                Comment


                  #9
                  Is it irony that the three packages needing updating are the update manager? LOL...

                  Please Read Me

                  Comment


                    #10
                    Indeed!
                    "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
                    – John F. Kennedy, February 26, 1962.

                    Comment

                    Working...
                    X