Some of us have self-built and programmed servers at home or at our disposal. One of the benefits to do-it-yourself servers is the lack of limits to what you can do with it.
I was updating a little script on mine sever and thought, maybe if I share it;
So here's my first contribution to this thread:
Notification of needed server package updates
One of my daily tasks is to check my server and see if it needs any package updates. I prefer not to fully automate the update process completely to avoid system breakage - I want my finger on the trigger so I can see what happens. My habit was to log into my server via ssh, run "sudo apt update && sudo apt list --upgradable" and see what needed upgrading. I got tired of doing this every morning, so I wrote this little bash script an added it as a root cronjob. Now every morning at 8 am my server lets me know what if anything is upgradable.
Here's the script:
Each line of the code does this:
Here's what the notification looks like;
I set the messages to not time out so anytime I get to my office, the message is waiting. I can review the list at my leisure and run any needed update when I'm ready.
ssh has to be set up both ways (server-to-office and office-to-server) to enable the message sending. I use a secure key method to allow ssh access so no passwords are stored in plain text.
I run this as root which could be considered insecure. If I were more cautious, I would enable the needed commands in sudoer for my server username and do it all that way. Either way, you'd have to know the password(s) to gain access to my desktop so I'm not bothering at this point.
If it matters, my server is currently on Ubuntu Server 14.04 and desktop KDEneon user. I do have one package - Plex Media Server - that's not from a ppa and wouldn't bring down the entire server if it failed, so it updates itself automatically via another script and cronjob.
I'm interested in comments and seeing if anyone else has something to contribute...
I was updating a little script on mine sever and thought, maybe if I share it;
- someone else will find it useful
- I might get suggestions on how to make it better
- I might get some new ideas from others
So here's my first contribution to this thread:
Notification of needed server package updates
One of my daily tasks is to check my server and see if it needs any package updates. I prefer not to fully automate the update process completely to avoid system breakage - I want my finger on the trigger so I can see what happens. My habit was to log into my server via ssh, run "sudo apt update && sudo apt list --upgradable" and see what needed upgrading. I got tired of doing this every morning, so I wrote this little bash script an added it as a root cronjob. Now every morning at 8 am my server lets me know what if anything is upgradable.
Here's the script:
Code:
[FONT=monospace][COLOR=#000000]#!/bin/bash[/COLOR] # apt update >/dev/null 2>&1 apt list --upgradable > upgrade.list if [[ "$(cat /root/upgrade.list)" != "Listing..." ]] then ssh office "DISPLAY=:0 notify-send -i package-install -t 0 'Server has updates waiting:' '`sed 's/\/.*//' /root/upgrade.list`'" else ssh office "DISPLAY=:0 notify-send -i package-install -t 0 'Server is up-to-date:' 'There are no pending updates.'" fi [/FONT]
- run "apt update" to freshen the package lists
- generate a list of pending updates and save it
- compare the saved list to an empty list (no updates in the list)
- if the list is non-empty, send the list ( with some trimming) to my office computer via notify-send
- if the list is empty, tell me that too
- done
Here's what the notification looks like;
I set the messages to not time out so anytime I get to my office, the message is waiting. I can review the list at my leisure and run any needed update when I'm ready.
ssh has to be set up both ways (server-to-office and office-to-server) to enable the message sending. I use a secure key method to allow ssh access so no passwords are stored in plain text.
I run this as root which could be considered insecure. If I were more cautious, I would enable the needed commands in sudoer for my server username and do it all that way. Either way, you'd have to know the password(s) to gain access to my desktop so I'm not bothering at this point.
If it matters, my server is currently on Ubuntu Server 14.04 and desktop KDEneon user. I do have one package - Plex Media Server - that's not from a ppa and wouldn't bring down the entire server if it failed, so it updates itself automatically via another script and cronjob.
I'm interested in comments and seeing if anyone else has something to contribute...
Comment