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