Showing posts with label shell scripting for beginner. Show all posts
Showing posts with label shell scripting for beginner. Show all posts

Monday, 30 December 2013

Scripts to Check Policies in Linux Such as Grub BootLoader Password, Prompting Password in Single user mode

(1) CTR ALT DEL SHUTDOWN POLICY


#!/bin/bash
echo "This script Check CTR ALT DEL POLICY Working or NOT "
f="/etc/inittab"

if [ -e $f ]
then
cd /etc

echo " U R in `pwd` "
s=`cat inittab | grep "^ca::ctrlaltdel:/sbin/shutdown -t3 -r now"`

if [ ! -n "$s" ]
then
echo " POLICY not Working "

else
echo "POLICY Working Properly "

fi
fi


 output
[root@CLIENT ~]# ./CtrAltDel.sh
This script Check CTR ALT DEL POLICY Working or NOT
 U R in /etc
POLICY Working Properly






(2) PASSWORD PROTECTING GRUB


#!/bin/bash
echo "This script check grub bootloader is password protected or not"
f="/boot/grub/grub.conf"

if [ -e $f ]
then
cd /boot/grub

echo " U R in `pwd` "
s=`cat grub.conf | grep "^password --md5"`

echo " PASSWORD OF GRUB IS  $s "
if [ ! -n "$s" ]

then
echo "Not Verified"

else
echo "Password  Implemented "

fi
fi


output

[root@CLIENT ~]# ./grub.sh
This script check grub bootloader is password protected or not
 U R in /boot/grub
 PASSWORD OF GRUB IS  password --md5 $1$cnO6W1$Oc3iMBjHIVVukIGkXkeFD0
Password  Implemented


(3) PROMPTING FOR PASSWORD IN SINGLE USER MODE


#!/bin/bash
echo "This script Check Prompting Password in Singl Usrmod POLICY Working or NOT "
f="/etc/inittab"

if [ -e $f ]
then
cd /etc

echo " U R in `pwd` "
s=`cat inittab | grep "^~~:S:wait:/sbin/sulogin"`

if [ ! -n "$s" ]
then
echo " POLICY not Working "

else
echo "POLICY Working Properly "

fi
fi


output
[root@CLIENT ~]# ./singleuser.sh
This script Check Prompting Password in Singl Usrmod POLICY Working or NOT
 U R in /etc
 POLICY not Working



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