Category Archives: RHEL7

NTP offset monitoring bash script

#!/bin/bash
# Created by Rodel
# 27/08/2020
MAIL=`which mail`
THIS_SERVER=`hostname -s`
RCPTS="rodel@test.com"
check_ntp_return_value () {
        ntpq_count=$(ntpq  -p |grep  -e '*'|awk  '{print $9}' | wc -l)
#       ntpq_count="0"
        if [ "$ntpq_count" -ne "0" ];
                then
                        check_ntp_offset;
                else
                        message=$(echo "No NTP master ip address assign <example: *192.168.0.x>. Please login to the server and check. Thank you.")
                        send_email "$message";
        fi
}
check_ntp_offset () {
        ntpq_p=$(ntpq  -p |grep  -e '*'|awk  '{print $9}')
        ntpq_p=${ntpq_p%.*}
#       ntpq_p="6001"
        ntpq_server=$(ntpq  -pn |grep  -e '*'|awk  '{print $1}' | sed 's/*//g')
        if [ "$ntpq_p" -gt "6000" ];
                then
                        message1=$(echo "Critical - `hostname` Offset value is $ntpq_p greater than 6000 milliseconds")
                        message2=$(ntp_sync)
                                                send_email "$message1 \n\n Executing ntpdate...\n$message2";
                else
                        exit 0
        fi
}

ntp_sync () {
#       ntpdate -q $ntpq_server >> /dev/null 2>&1
        ntpdate -q $ntpq_server
}
send_email () {
        STR2="${1}"
        echo -e "${STR2}" | ${MAIL} -s "[${THIS_SERVER}] NTP Synchronization Alert" "${RCPTS}"
}
check_ntp_return_value

Extend LVM partition with same device

Existing Partition Table

[root@server ~]# fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41861119 20417536 8e Linux LVM

Example: I want to add /dev/sda3

#fdisk /dev/sda
Command (m for help): m
Command (m for help): n
Command (m for help): t
Command (m for help): 8e
Command (m for help): w

#reboot

Create Physical Volume
pvcreate /dev/sda3

Extend existing Volume Group

[root@server ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz–n- <19.47g 0

for the vgs output we will extend rhel volume group
#vgextend rhel /dev/sda3

Extend existing Logical Volume

#lvextend /dev/rhel/root /dev/sda3

In this example I will expand the mount points for root partition
[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 12M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/rhel-root 18G 3.3G 15G 19% /
/dev/sda1 497M 172M 325M 35% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0

#xfs_growfs /dev/mapper/rhel-root

#reboot