Monday 30 December 2013

Scripts to Check Linux Logs Message such as Mail Events,Authentication Message Logs

(1)  Display General Message Logs

#!/bin/bash
echo  "This script shows the General Message Logs "
f= "/var/log/messages"

if [  -e $f  ]
then

cd /var/log
echo  " Welcome to the LOG directory `pwd`  "

head -5 messages  > sample1
echo "Demo of the logs message "

cat sample1
echo "task complete "

fi

ouptput
This script shows the General Message Logs
 Welcome to the LOG directory /var/log 
Demo of the logs message
Dec 29 03:45:20 CLIENT syslogd 1.4.1: restart.
Dec 29 03:45:20 CLIENT nmbd[2423]:   Got SIGHUP dumping debug info.
Dec 29 03:45:20 CLIENT nmbd[2423]: [2013/12/29 03:45:20, 0] nmbd/nmbd_workgroupdb.c:dump_workgroups(282)
Dec 29 03:45:20 CLIENT nmbd[2423]:   dump_workgroups()
Dec 29 03:45:20 CLIENT nmbd[2423]:    dump workgroup on subnet       10.0.2.15: netmask=  255.255.255.0:
task complete


(2)  Display Authentication Message Logs


#!/bin/bash
echo "This script shows the Authentication Message Logs "
f="/var/log/secure"

if [ -e $f  ]
then

cd /var/log
echo " Welcome to the LOG directory `pwd`  "

head -5 secure  > sample2
echo "Demo of the logs message "

cat sample2
echo "task complete "
fi

output
[root@CLIENT ~]# ./secure.sh
This script shows the Authentication Message Logs
 Welcome to the LOG directory /var/log 
Demo of the logs message
Dec 30 04:18:34 CLIENT sshd[2312]: Server listening on :: port 22.
Dec 30 04:18:34 CLIENT sshd[2312]: Server listening on 0.0.0.0 port 22.
Dec 30 04:20:27 CLIENT gdm[2593]: pam_unix(gdm:session): session opened for user root by (uid=0)
Dec 30 05:21:47 CLIENT su: pam_unix(su-l:session): session opened for user alice by root(uid=0)
Dec 30 05:22:20 CLIENT su: pam_unix(su-l:session): session closed for user alice
task complete


(3) Display Mail Event Logs

#!/bin/bash
echo "This script shows the  Mail Events Logs "
f="/var/log/maillog"
if [ -e $f  ]
then
cd /var/log
echo " Welcome to the LOG directory `pwd`  "
head -5 maillog  > sample3
echo "Demo of the logs message "
cat sample3
echo "task complete "
 
output
root@CLIENT ~]# ./maillog.sh
This script shows the  Mail Events Logs
 Welcome to the LOG directory /var/log 
Demo of the logs message
Dec 29 03:45:35 CLIENT sendmail[3685]: rBSMFZHo003685: from=root, size=228, class=0, nrcpts=1, msgid=<201312282215.rBSMFZHo003685@CLIENT>, relay=root@localhost
Dec 29 03:45:35 CLIENT sendmail[3686]: rBSMFZTx003686: from=<root@CLIENT>, size=457, class=0, nrcpts=1, msgid=<201312282215.rBSMFZHo003685@CLIENT>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Dec 29 03:45:35 CLIENT sendmail[3685]: rBSMFZHo003685: to=root, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30228, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (rBSMFZTx003686 Message accepted for delivery)
Dec 29 03:45:35 CLIENT sendmail[3687]: rBSMFZTx003686: to=<root@CLIENT>, ctladdr=<root@CLIENT> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30647, dsn=2.0.0, stat=Sent
Dec 29 04:02:06 CLIENT sendmail[3833]: rBSMW3Gb003833: from=root, size=3843, class=0, nrcpts=1,
task complete


1 comment: