Update Linux Remotely

ssh-copy-id root@matx01lins02.nerdydrunk.net
ssh root@matx01lins01.nerdydrunk.net "yum -y upgrade"
ssh root@matx01lins01.nerdydrunk.net "reboot"
ssh root@matx01lins01.nerdydrunk.net "rpm -qa kernel && uname -a"
ssh root@matx01lins01.nerdydrunk.net "yum -y erase kernel-2.6.32-504.el6.x86_64"
ssh root@matx01lins01.nerdydrunk.net "cd ./vmware-tools-distrib/ && ./vmware-install.pl -d"


The following script can be used to receive an email when updates are available on a Linux system that uses YUM. This could also easily be modified to work on an other type of Linux system.

[tingalls@MATX01LIMO01 ~]$ cat check-updates.sh
#!/bin/bash

#
# Create a diretory /mnt/scratch and add this file to the root crontab
#
### [ec2-user@ip-10-4-0-247 ~]$ sudo crontab -l
### 2 2 * * * /home/ec2-user/check-updates.sh
#

if [[ $EUID -ne 0 ]]; then
	echo -e "\nUnfortunetly this command must be run as root.\n"
	exit 1
fi

hstring="`uname -n` available updates"

date > /mnt/scratch/update-report.txt
echo -e "" >> /mnt/scratch/update-report.txt

yum update --assumeno --skip-broken | sed -n -e '/===/,$p' | sed -e '/Exiting on user Command/,$d' >> /mnt/scratch/available-updates.txt

if grep -i package /mnt/scratch/available-updates.txt
then
	#echo -e "\n\nUpdates available.\n\n"
	cat /mnt/scratch/available-updates.txt >> /mnt/scratch/update-report.txt
	echo -e "\n" >> /mnt/scratch/update-report.txt
	mail -s "$hstring" USERNAME@DOMAIN.COM < /mnt/scratch/update-report.txt
else
	#echo -e "\n\nNo updates available.\n\n"
	cd
fi

rm /mnt/scratch/available-updates.txt
rm /mnt/scratch/update-report.txt

[tingalls@MATX01LIMO01 ~]$