A while back I had started to experiment with a way to get e-mail
notifications from my servers when up2date detected that new packages
were available. I am running a series of Fedora Core 1,2, and 3
boxes and it seems that the updates come quite frequently.
I decided that this weekend I would sit down and write a new bash
script that could be run daily by cron. Here’s what I wrote:
#!/bin/bash
# First lets check with up2date …# have up2date list the available packages …
up2dateOutput=`up2date –nox -l`# now check to see if packages are listed …
firstUpdatePackage=`echo “$up2dateOutput” | grep -A1
“\-\-\-\-\-\-\-\-\-\-” | awk ‘{if (NR==2) print $1}’`
# take the
output,
# grep for the long hyphen divider
# grabbing that line and the
next line,
# awk the second line to see if there
# is a package name at the
beginning#echo “First package: |$firstUpdatePackage|”
if [ ! -z “$firstUpdatePackage” ]
# there is a package name
then
#echo “Sending e-mail …”
nodeName=`uname -n` # get the host name
mailSubject=”Up2date – “$nodeName
# create the e-mail subject line
`echo “$up2dateOutput” | mail -s “$mailSubject” root`
# send the e-mail to root
fi
exit 0
So far, it appears to do exactly what I had hoped … an e-mail notice
when there are packages that can be updated on my servers!