Thursday, December 29, 2016

Script - Collects log message for 2 days - today and the day before from /var/adm/messages

Tested on Solaris 10
[sam@sinf-mg-v01]$ cat var_messages.sh
#!/bin/bash
# @expanor, LLC
# Sam Bhusal
# Collects log message for 2 days - today and the day before from /var/adm/messages
# Thu Dec 29 13:21:57 EST 2016
#
LOGFILE="logs/MESSAGES/messages_`date "+%m%d%y_time.%H-%M-%S.log"`"
#SUDO=/usr/local/bin/sudo
# Need to get log file for two days.
AAJA="`date '+%b %e'`"
# Assume GNU coreutils is present on the system
HIJO=`TZ=GMT+24 date +'%b %e'`
#for i in 10.22.112.11 10.22.112.11
for i in `cat ../etc/hosts.ip | grep -v "#" | awk '{print$1}'`
do
        echo "                    " >>$LOGFILE
        echo "                    "
        echo "Please wait ... Checking on $i server" >> $LOGFILE
        echo "Please wait ... Checking on $i server"
        ssh -q $i /usr/local/bin/sudo /usr/bin/cat /var/adm/messages | egrep "$HIJO|$AAJA" >> $LOGFILE
        echo "__________________________End of the Log FIle_____________________">> $LOGFILE
        echo "                     " >>$LOGFILE
done
echo "Reading Log file"
echo "Please wait ...."
echo ""
more $LOGFILE
[sam@my-sunserv-v01]$

No comments:

Post a Comment