Update Linux Remotely

ssh-copy-id [email protected]
ssh [email protected] "yum -y upgrade"
ssh [email protected] "reboot"
ssh [email protected] "rpm -qa kernel && uname -a"
ssh [email protected] "yum -y erase kernel-2.6.32-504.el6.x86_64"
ssh [email protected] "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" [email protected] < /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 ~]$