Monday, April 27, 2015

RHEL7- Reset forgot root password

Boot your system and, on the GRUB boot screen, where count begins, press any key and press the e key to edit.
Scroll down with the arrow down key and go to the line where it says "linux16. Go to the end of the line and add the following entry. rd.break selinux=0

--> add " rd.break selinux=0 "  to the end of the linux16 line

Once its added type  ctrl-x  to save and exit.

You will be at the shell prompt. Just type to following commands below to reset the password.

# mount -o remount,rw /sysroot
# chroot /sysroot
# passwd
# exit / exit


Machine reboot's  (selinux = disabled and will be enabled at next reboot) automatically after that.

Note: Run " touch /.autorelabel" command in order to set the SELinux context  ( to update SELinux parameters) of the files to restore properly after reboot.

Tuesday, April 21, 2015

ntp check running as cron job

$ more check_ntpd.sh
#!/bin/sh
###################################################################################
#
#  SCRIPT: check_ntpd.sh
#  Author:  Sam
#  Date:    Fri Apr 17 15:10:02 EDT 2015
#  Usage:   ./check_ntpd.sh
#  Detail:  Include hosts that you want to check ntp status on ntp.chk file and run the script
#  $ more ntp.chk
#  server01
#  server02
#  server03
#  --------------- Change Log ----------------
#
#
###################################################################################
#
for i in `cat ntp.chk`
do
        ssh -tq $i '/usr/bin/sudo tail -50 /var/log/messages | grep -i ntp | grep "slew\|synchronized" | tail -1'
        #ssh -tq $i '/usr/bin/sudo tail -50 /var/log/messages | grep -i ntp | grep "slew\synchronized" | tail -1'
        #echo $i; ssh -tq $i /usr/sbin/ntpdate -q ntp1.ecap.cciio | grep -v stratum |  awk -F] '{print $1"]"}' | tr "\n" " "
        #echo "Checking: $i:"; ssh -tq $i /usr/sbin/ntpdate -q ntp1.ecap.cciio | grep -v stratum |  awk -F] '{print $1"]"}' | tr "\n"
" "
        #ssh -tq $i /usr/sbin/ntpdate -q ntp1.ecap.cciio | grep -v stratum |  awk -F] '{print $1"]"}' | tr "\n" " \t"
        #echo "on host: $i"
        # sudo tail --lines=40 /var/log/messages | grep -i ntp | grep "slew\|synchronized" | tail --lines=1
done

Checking ntp servers

$ cat check_ntp_server.sh
#!/bin/sh
###################################################################################
#      
#  SCRIPT:  Checks Internal and external DNS query.
#  Author:  Sam
#  Date:    Wed Apr 17 07:29 EDT 2015
#  Usage:   Simply run ./check_ntp_server.sh script.
#  Detail:  There is a file ntp.servers which includes ntp servers.
#  $ more ntp.servers
#  ntpserv01
#  ntpserv02
#  ntpserv03
#  ntpserv04    
#
for i in `cat ntp.servers`
do
        echo " "
        echo "Checking $i"
        ssh -q $i /usr/sbin/ntpq -p; echo " ";  echo "Checking FS"; df -h
        #ssh -q $i /usr/sbin/ntpq -p; echo " ";  echo "Checking FS"; df -h; echo ""; echo "Top Output"; top
done

Checking DNS internal and external


$ more chk_dns_record.sh
#!/bin/sh
###################################################################################
#  
#  SCRIPT:  Checks Internal and external DNS query.
#  Author:  Sam                                                                                                            
#  Date:    Wed Apr 15 14:42:55 EDT 2015
#  Usage:   Simply run ./dns_chk_in.sh script.
#  Detail:  There is a file dns.chk for external DNS and dns_chk_in for internal.
#           Add some domain on dns.chk and some host from I-Center on dns_chk_in.
#  $ more  dns.chk      
#  abc.com        
#  yahoo.com      
#  $ more dns_chk_in                                                                                                      
#  myserv1
#  myserv2  
#  --------------- Change Log ----------------
#
#        
###################################################################################
#
echo "Checking Mail Relay"
sleep 2
echo "Checking mail delivery from `hostname`" | mailx -s "Checking Mail Relay" sam@mycompany.com
echo
##############################################
echo "Checking external DNS record"
sleep 2
for i in `cat dns.chk`
do
        nslookup $i | tail -3
done
##############################################
echo "Please wait, checking internal DNS query"
sleep 2
echo
echo "Plase wait, checking DNS query"
rm dns_chk_in.rev
for i in `cat dns_chk_in`
do
        nslookup $i-int.expanor.local | tail -3 | tr "\n"   " "
        echo
        nslookup $i-int.expanor.local | tail -2 | grep -v server | awk '{print $2}'>>dns_chk_in.rev
done
###############################################
echo "Now, checking reverse DNS lookup"
echo
echo "Checking Reverse Look up"
for i in `cat dns_chk_in.rev`
do
        nslookup $i| head -4 | tail -1
done