May 16

Linux: Checking for updates on multiple servers and emailing the results

The following script checks for updates on the server it is executing from along with multiple servers. It collects the data into a single file and then emails the information.
Although this script uses yum, you should be able to do the same thing with apt-get.
Prerequisite: Sendmail

*Note the dos2unix command.  If you do not add this, Sendmail will send your file as a .dat attachment rather than adding your file contents to the body of your message.

vi chkup.sh
echo “Available Centos Server Updates:” > crslt.txt
echo -e “n” >> crslt.txt
echo “SRV01” >> crslt.txt
yum check-update >> crslt.txt
echo -e “n” >> crslt.txt
echo “SVR02” >> crslt.txt
ssh root@svr02 ‘yum check-update’ >> crslt.txt
echo -e “n” >> crslt.txt
echo “SVR03” >> crslt.txt
ssh root@svr03 ‘yum check-update’ >> crslt.txt
echo -e “n” >> crslt.txt
echo “SVR04” >> crslt.txt
ssh root@svr04 ‘yum check-update’ >> crslt.txt
sed “/Loaded plugins:/d” crslt.txt > tmp ; mv tmp crslt.txt
sed “/Loading mirror/d” crslt.txt > tmp ; mv tmp crslt.txt
sed “/* base:/d” crslt.txt > tmp ; mv tmp crslt.txt
sed “/* extras:/d” crslt.txt > tmp ; mv tmp crslt.txt
sed “/* updates:/d” crslt.txt > tmp ; mv tmp crslt.txt
dos2unix crslt.txt
mail -s ‘Daily Centos Server Update Report’ [email protected] < crslt.txt

Then add this to a cron job
The following example will run every Monday through Friday (1-5) at 6 a.m.:
crontab -e
0 6 * * 1-5 /root/scripts/chkup.sh #CENTOS update checking of multiple servers


Copyright 2021. All rights reserved.

Posted May 16, 2012 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B