Script that notifies via email when your server has updates
If you are the administrator of a server then you definitely understand the importance of keeping your system updated always.
The following script will send you a mail whenever your server needs an update. The content of the mail will list out all the available updates.
#!/bin/bash # Author: AppleGrew # Site: www.applegrew.com # License: GPL v2 yum check-update > /tmp/checkupdate.log if [[ $? == 100 ]] then mail -s "New YUM updates available" -r email@example.com $MAILTO < /tmp/checkupdate.log fi
- This script has been tested on CentOS 6 but should run on all RedHat based systems.
- In the above script, change firstname.lastname@example.org to any valid email id which your server is authorized to send. This the email id for the ‘From’ field. For example you can not set this to (say) email@example.com. Since Google did not authorize your server to send emails on behalf of gmail.com.
- Copy this script to some directory in your server and give it execute permission.
- Now schedule a cron job for this script. You can set this job for any user, since this script does not need root privileges.
- In the cronjob make sure to set the MAILTO environment variable. The script uses this variable to determine the recipient of the notification.
MAILTOfirstname.lastname@example.org 0 0 * * * /home/user1/checkupdate.sh