Popular Posts

Jan 25, 2017

Script to track configuration change in Solaris servers

Script to track configuration change in Solaris servers

       -  Purpose of this script - Defined configuration change will be notified to the listed recipient through e-Mail      
       -  This script will track the modification of configuration files in server.
       -  List of configuration files needs to be seeded inside the script - as per our requirement
       -  Four config files are included (vfstab,system,ntp.conf,resolv.conf) - we can include more files
       -  Schedule the script in cron to run every one hour
       -  If we need to change the schedule instead of one hour, then change the seconds (3660) mentioned  in script to appropriate
       -  If any one of the configuration files modified within one hour, we will receive a mail with those details.
       -  Detailed report will get attached in e-Mail
       -  Example, if we would like to run the script every 15 minutes, then change the 3600 to 900 seconds



 #!/bin/ksh
DIR=/var/tmp/confbkp
STAMP=`date +%d.%m.%Y.%H.%M`
ConfList=$DIR/ConfList
PRVHOUR=`perl -MPOSIX=strftime -le 'print strftime("%m%d%H%M", localtime(time-3660))'`

mkdir -p $DIR
> $DIR/tmp.out
echo "
File changes in last one hour - `uname -n`
=============================="> $DIR/result.out

#Define what all configuration files needs to be monitored.
echo "/etc/vfstab
/etc/system
/etc/resolv.conf
/etc/inet/ntp.conf" > $ConfList

#Create a file with One Hour old time stamp
touch -mt $PRVHOUR $DIR/stampfile

#Compare the config files one by one with current time stamp
for i in `cat $ConfList` ; do
COUNT=`find $i -newer /var/tmp/confbkp/stampfile -local -print | wc -l`
if [ $COUNT -eq 1 ] ; then
echo "$i" >> $DIR/tmp.out
fi
done

if [ -s $DIR/tmp.out ] ; then
cat $DIR/tmp.out >> $DIR/result.out
else
echo "No configuration chnages for the past one hour" >> $DIR/result.out
fi

#Sending the attachement in mail
cd $DIR
unix2dos result.out result.`uname -n`.txt
uuencode result.`uname -n`.txt result.`uname -n`.txt | mailx -s "Configuration - Audit Rport $STAMP `uname -n`" judi@gmail.com



No comments:

Post a Comment

Popular Posts