Bash script to check for automatic yum updates
#!/bin/bash
########################################
# This script will check for available package-
# update for Centos/Redhat 5 sytem
# Written by : Fosiul Alam
# Version :1.0
# Created Date : 27/08/2009
# Last Modification : 27/08/2009
#########################################
########################################
# Command use : yum -e0 -d0 check-update
# Usage : /yum-script.sh
########################################
_GET_HOSTNAME=`hostname`
_TODAY=`date '+%A'`
_YESTERDAY=`date '+%A' --date='1 day ago'`
_CMD_FILE=/tmp/tmp.txt.$_TODAY
_CMD_YESTERDAY_FILE=/tmp/tmp.txt.$_YESTERDAY
_EMAIL_REPORTS=/tmp/yum-reports.txt
#Delete Yesterday's tmp.txt file( Housekeeping)
if [ -e $_CMD_YESTERDAY_FILE ]
then
rm $_CMD_YESTERDAY_FILE
fi
#check if yum-reports.txt file exists or not
if [ -e $_EMAIL_REPORTS ]
#if the file exists then delete the file
then
rm $_EMAIL_REPORTS
#Create the file again
touch $_EMAIL_REPORTS
#Initialize yum command into the variables
yum -e0 -d0 check-update >$_CMD_FILE
#Check if file is exists and not empty
if [ -s $_CMD_FILE ]
then
#_EMAIL_REPORTS=/tmp/yum-reports.txt
echo "Daily($_TODAY) Yum Updates Reports for $_GET_HOSTNAME " >> $_EMAIL_REPORTS
echo "There are some updates availabe for your attention" >> $_EMAIL_REPORTS
echo "###########Updates Are###########" >> $_EMAIL_REPORTS
cat $_CMD_FILE >> $_EMAIL_REPORTS
echo "############## Updates Finished#####" >> $_EMAIL_REPORTS
cat $_EMAIL_REPORTS | mail -s "Yum Reports For $_GET_HOSTNAME " fosiul@gmail.com
else
echo " NO Updates for $_TODAY" >/dev/null 2>&1
fi
fi
This entry was posted
on Thursday, August 27th, 2009 at 12:15 pm and is filed under Bash Script, Linux.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.