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