May 23

Linux: Running available updates on multiple servers and emailing the results

The following script runs the available 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 runup.sh
echo “Centos Software Update Results” > rrslt.txt
echo -e “n” >> rrslt.txt
echo “SRV1” >> rrslt.txt
yum update -y >> rrslt.txt
echo -e “n” >> rrslt.txt
echo “SRV2” >> rrslt.txt
ssh root@SRV2 -t ‘yum update -y’ >> rrslt.txt
echo -e “n” >> rrslt.txt
echo “SRV3” >> rrslt.txt
ssh root@SRV3 -t ‘yum update -y’ >> rrslt.txt
echo -e “n” >> rrslt.txt
echo “SRV4” >> rrslt.txt
ssh root@SRV4 -t ‘yum update -y’ >> rrslt.txt
sed “/Loaded plugins:/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/Loading mirror/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/* base:/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/* extras:/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/* updates:/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
sed “/Setting up Update Process/d” rrslt.txt > tmp2 ; mv tmp2 rrslt.txt
dos2unix rrslt.txt
mail -s ‘Centos Server Update Results’ [email protected] < rrslt.txt


Copyright 2021. All rights reserved.

Posted May 23, 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