Created
January 28, 2016 10:08
-
-
Save DavidGarciaCat/b52aade8f5d7d41f4a28 to your computer and use it in GitHub Desktop.
GNU/Linux Shell Script that checks if there are new updates available for the Operating System
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| TEMP_FILE=/tmp/available-updates.log | |
| apt-get update | |
| sleep 5 | |
| dpkg --get-selections | xargs apt-cache policy {} | grep -1 Installed | sed -r 's/(:|Installed: |Candidate: )//' | uniq -u | tac | sed '/--/I,+1 d' | tac | sed '$d' | sed -n 1~2p > $TEMP_FILE | |
| sleep 5 | |
| FILE_SIZE=`ls -lha /tmp/available-updates.log | cut -d' ' -f5` | |
| if [ $FILE_SIZE -eq 0 ] | |
| then | |
| rm $TEMP_FILE | |
| else | |
| cat $TEMP_FILE | /usr/bin/mailx -v \ | |
| -r "FROM_ADDRESS" \ | |
| -s "[ SERVER_NAME ] Server Updates available" \ | |
| -S smtp="SMTP_SERVER:SMTP_PORT" \ | |
| -S smtp-use-starttls \ | |
| -S smtp-auth=login \ | |
| -S smtp-auth-user="SMTP_USER" \ | |
| -S smtp-auth-password="SMTP_PASSWORD" \ | |
| -S ssl-verify=ignore \ | |
| RECIPIENT_ADDRESS | |
| sleep 5 | |
| rm $TEMP_FILE | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment