RHEL5 – Poor Man’s Auto Update with “yum”

A quick and dirty some might find helpful. We have our bleeing edge development box that I want updated via cron. Maybe there’s some fancy GUI way to do this, but to heck with that. I am coder!

So, I just want to set this up as a cron job. It’s e-mailing me (crude) to let me know it ran. Good enough for me, for now (maybe forever), I say.

Here’s a program I called “yupdate”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
#
#
LOGFILE="/var/log/yupdate"
 
# Start stamp is in current locale (%c) format
# Notice I am appending (>>) so this log will grow over time. Keep an eye on it.
START_STAMP=`date +%c`
echo ${START_STAMP} >> ${LOGFILE}
 
# The actual update itslef; -y = say yes to everything
/usr/bin/yum -y update >> ${LOGFILE} 2>&1
 
# Put a little end time stamp in there
STOP_STAMP=`date +%c`
echo ${STOP_STAMP} >> ${LOGFILE}
 
# Send a note to myself. Hopefully I'll be sleeping:
echo "Ran yum update log file is ${LOGFILE}" | mail -s "serverX yum update finished" foo@email.com

That’s it. Assuming I set this up to run each Sunday night, I should know Monday morning first thing everything that gets broken by the upgrade. Whoops, I mean, I’ll be resting easy that I am completely up to date. (Crossing fingers…)