Pages

AIX Pre & Post-Reboot Validation Scripts

The two Bash scripts automate the collection and comparison of system information on AIX servers before and after a reboot to ensure system integrity and detect any discrepancies.

Scripts:
os_pre_validation.sh:
Collects system details such as hostname, OS version, CPU, memory, disk info, filesystem mounts, network interfaces, VGs & LVs, running services, open ports, and cluster status.
Saves the data to a timestamped log file in logs/.

os_post_validation.sh:
Collects the same system information after a reboot.
Compares it with the most recent pre-reboot log.
Generates a detailed comparison report highlighting matches (OK) and mismatches (MISMATCH).

Usage:
./os_pre_validation.sh <servername>   # Run before reboot
./os_post_validation.sh <servername>  # Run after reboot

Key Benefits:
  • Automated validation of system state across reboots.
  • Helps detect configuration changes, missing services, or network/disks issues.
  • Provides a clear, timestamped log and comparison report for auditing.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
# =============================================================
# AIX Pre-Reboot Validation Script
# Author : adminCtrlX
# Version: 1.0
# Description: Collects system, disk, network, VG & LV info 
#              before reboot.
# Usage: ./os_pre_validation.sh <servername>
# =============================================================

if [ $# -lt 1 ]; then
    echo "Usage: $0 <servername>"
    exit 1
fi

server="$1"
timestamp=$(date +'%Y%m%d_%H%M%S')
log_dir="logs"
mkdir -p "$log_dir"
pre_file="${log_dir}/${server}_pre_${timestamp}.log"

echo "Collecting pre-reboot data for $server..."

ssh -q -o ConnectTimeout=10 "$server" bash <<'EOF' > "$pre_file" 2>&1

echo "HOSTNAME=$(hostname)"
echo "OS_VERSION=$(oslevel -s)"
echo "ARCH=$(uname -p)"
echo "UPTIME=$(uptime | awk '{print $3}') Days"

CPU_CORES=$(lsdev -Cc processor | grep -c Available)
CPU_MODEL=$(lsattr -El proc0 | awk '/type/ {print $2}')
echo "CPU_CORES=$CPU_CORES"
echo "CPU_MODEL=$CPU_MODEL"

MEM_TOTAL=$(lsattr -El mem0 | awk '/goodsize/ {print $2}')
MEM_FREE=$(svmon -G | awk '/memory/ {getline; print int($4*4/1024)}')
echo "MEM_TOTAL_MB=$MEM_TOTAL"
echo "MEM_FREE_MB=$MEM_FREE"

for d in $(lsdev -Cc disk | awk '{print $1}'); do
    sz_mb=$(bootinfo -s $d 2>/dev/null)
    sz_gb=$( [ -n "$sz_mb" ] && echo "scale=2; $sz_mb/1024" | bc || echo "0" )
    echo "DISK_DETAIL_$d=${sz_gb}G"
done

df -g | tail -n +2 | wc -l | awk '{print "FILESYSTEM_TOTAL="$1}'
mount | awk '{print "FILESYSTEM_MOUNTS_"$1"="$2}'
mount | grep -i nfs | awk '{print "NFS_MOUNTS_"$1"="$2}'

ifconfig -a | awk '
/^[a-zA-Z]/ {iface=$1}
/inet / {
    ip=$2
    mask=$4
    print "NETWORK_INTERFACE_" iface "=IP=" ip " SubnetMask=" mask
}' 

for vg in $(lsvg -o); do
    echo "VG_ONLINE_$vg=online"
done

for vg in $(lsvg -o); do
    lsvg -l $vg | awk -v vg="$vg" 'NR>2 {print "LV_STATUS_" vg "_" $1 "=Type="$2" State="$NF}'
done

lssrc -a | awk '/active/ {print "SERVICE_RUNNING_"$1"=active"}'

netstat -an | awk '/LISTEN/ {split($4,a,":"); print "OPEN_PORT_"a[length(a)]"=listening"}'

if command -v clRGinfo >/dev/null 2>&1; then
    clRGinfo | awk '/Resource|Node|State/ {print "POWERHA_CLUSTER_STATUS=" $0}'
else
    echo "POWERHA_CLUSTER_STATUS=CommandNotFound"
fi

if command -v mmgetstate >/dev/null 2>&1; then
    echo "GPFS_CLUSTER_STATUS=$(mmgetstate -aL | tr '\n' ' ' | sed 's/  */ /g')"
else
    echo "GPFS_CLUSTER_STATUS=CommandNotFound"
fi

EOF

echo "Pre-reboot check completed for $server."
echo "Log saved to $pre_file"

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#!/bin/bash
# =============================================================
# AIX Post-Reboot Validation Script
# Author : adminCtrlX
# Version: 1.0
# Description: Collects system info after reboot and compares 
#              with pre-reboot log.
# Usage: ./os_post_validation.sh <servername>
# =============================================================

if [ $# -lt 1 ]; then
    echo "Usage: $0 <servername>"
    exit 1
fi

server="$1"
timestamp=$(date +'%Y%m%d_%H%M%S')
log_dir="logs"
mkdir -p "$log_dir"

pre_file=$(ls -1t ${log_dir}/${server}_pre_*.log 2>/dev/null | head -1)
if [ -z "$pre_file" ]; then
    echo "No pre-reboot log found. Run os_pre_validation.sh first!"
    exit 1
fi

post_file="${log_dir}/${server}_post_${timestamp}.log"
compare_file="${log_dir}/${server}_comparison_${timestamp}.log"

echo "Collecting post-reboot data for $server..."

ssh -q -o ConnectTimeout=10 "$server" bash <<'EOF' > "$post_file" 2>&1

echo "HOSTNAME=$(hostname)"
echo "OS_VERSION=$(oslevel -s)"
echo "ARCH=$(uname -p)"
echo "UPTIME=$(uptime | awk '{print $3}') Days"

CPU_CORES=$(lsdev -Cc processor | grep -c Available)
CPU_MODEL=$(lsattr -El proc0 | awk '/type/ {print $2}')
echo "CPU_CORES=$CPU_CORES"
echo "CPU_MODEL=$CPU_MODEL"

MEM_TOTAL=$(lsattr -El mem0 | awk '/goodsize/ {print $2}')
MEM_FREE=$(svmon -G | awk '/memory/ {getline; print int($4*4/1024)}')
echo "MEM_TOTAL_MB=$MEM_TOTAL"
echo "MEM_FREE_MB=$MEM_FREE"

for d in $(lsdev -Cc disk | awk '{print $1}'); do
    sz_mb=$(bootinfo -s $d 2>/dev/null)
    sz_gb=$( [ -n "$sz_mb" ] && echo "scale=2; $sz_mb/1024" | bc || echo "0" )
    echo "DISK_DETAIL_$d=${sz_gb}G"
done

df -g | tail -n +2 | wc -l | awk '{print "FILESYSTEM_TOTAL="$1}'
mount | awk '{print "FILESYSTEM_MOUNTS_"$1"="$2}'
mount | grep -i nfs | awk '{print "NFS_MOUNTS_"$1"="$2}'

ifconfig -a | awk '
/^[a-zA-Z]/ {iface=$1}
/inet / {
    ip=$2
    mask=$4
    print "NETWORK_INTERFACE_" iface "=IP=" ip " SubnetMask=" mask
}' 

for vg in $(lsvg -o); do
    echo "VG_ONLINE_$vg=online"
done

for vg in $(lsvg -o); do
    lsvg -l $vg | awk -v vg="$vg" 'NR>2 {print "LV_STATUS_" vg "_" $1 "=Type="$2" State="$NF}'
done

lssrc -a | awk '/active/ {print "SERVICE_RUNNING_"$1"=active"}'

netstat -an | awk '/LISTEN/ {split($4,a,":"); print "OPEN_PORT_"a[length(a)]"=listening"}'

if command -v clRGinfo >/dev/null 2>&1; then
    clRGinfo | awk '/Resource|Node|State/ {print "POWERHA_CLUSTER_STATUS=" $0}'
else
    echo "POWERHA_CLUSTER_STATUS=CommandNotFound"
fi

if command -v mmgetstate >/dev/null 2>&1; then
    echo "GPFS_CLUSTER_STATUS=$(mmgetstate -aL | tr '\n' ' ' | sed 's/  */ /g')"
else
    echo "GPFS_CLUSTER_STATUS=CommandNotFound"
fi

EOF

# ----------------- Comparison -----------------
echo "==================== PRE vs POST COMPARISON for $server ====================" > "$compare_file"

while IFS='=' read -r key pre_value; do
    [ -z "$key" ] && continue
    post_value=$(grep "^$key=" "$post_file" | cut -d= -f2-)
    [ -z "$post_value" ] && post_value="NotFound"

    echo "$key :" >> "$compare_file"
    echo "Pre Check  : $pre_value" >> "$compare_file"
    echo "Post Check : $post_value" >> "$compare_file"

    if [ "$pre_value" = "$post_value" ]; then
        status="OK"
    else
        status="MISMATCH"
    fi
    echo "Status=$status" >> "$compare_file"
    echo "----------------------------------------------------------------" >> "$compare_file"
done < "$pre_file"

echo "Post-reboot check completed for $server."
echo "Comparison report saved to $compare_file"
cat "$compare_file"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Script Output:

root@indjump01(/tmp)# ./test aixlpar01
Collecting pre-reboot data for aixlpar01...
Pre-reboot check completed for aixlpar01.
Log saved to logs/aixlpar01_pre_20251027_064200.log
root@indjump01(/tmp)# ./test1 aixlpar01
Collecting post-reboot data for aixlpar01...
Post-reboot check completed for aixlpar01.
Comparison report saved to logs/aixlpar01_comparison_20251027_064216.log
==================== PRE vs POST COMPARISON for aixlpar01 ====================
HOSTNAME :
Pre Check  : aixlpar01
Post Check : aixlpar01
Status=OK
----------------------------------------------------------------
OS_VERSION :
Pre Check  : 7300-03-01-2520
Post Check : 7300-03-01-2520
Status=OK
----------------------------------------------------------------
ARCH :
Pre Check  : powerpc
Post Check : powerpc
Status=OK
----------------------------------------------------------------
UPTIME :
Pre Check  : 20 Days
Post Check : 20 Days
Status=OK
----------------------------------------------------------------
CPU_CORES :
Pre Check  : 1
Post Check : 1
Status=OK
----------------------------------------------------------------
CPU_MODEL :
Pre Check  : PowerPC_POWER9
Post Check : PowerPC_POWER9
Status=OK
----------------------------------------------------------------
MEM_TOTAL_MB :
Pre Check  : 6144
Post Check : 6144
Status=OK
----------------------------------------------------------------
MEM_FREE_MB :
Pre Check  : 15
Post Check : 15
Status=OK
----------------------------------------------------------------
DISK_DETAIL_hdisk27 :
Pre Check  : 50.00G
Post Check : 50.00G
Status=OK
----------------------------------------------------------------
DISK_DETAIL_hdisk28 :
Pre Check  : 50.00G
Post Check : 50.00G
Status=OK
----------------------------------------------------------------
DISK_DETAIL_hdisk29 :
Pre Check  : 79.99G
Post Check : 79.99G
Status=OK
----------------------------------------------------------------
DISK_DETAIL_hdisk30 :
Pre Check  : 79.99G
Post Check : 79.99G
Status=OK
----------------------------------------------------------------
DISK_DETAIL_hdisk31 :
Pre Check  : 79.99G
Post Check : 79.99G
Status=OK
----------------------------------------------------------------
DISK_DETAIL_hdisk32 :
Pre Check  : 79.99G
Post Check : 79.99G
Status=OK
----------------------------------------------------------------
FILESYSTEM_TOTAL :
Pre Check  : 11
Post Check : 11
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_node :
Pre Check  : mounted
Post Check : mounted
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/hd4 :
Pre Check  : /
Post Check : /
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/hd2 :
Pre Check  : /usr
Post Check : /usr
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/hd9var :
Pre Check  : /var
Post Check : /var
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/hd3 :
Pre Check  : /tmp
Post Check : /tmp
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/hd1 :
Pre Check  : /home
Post Check : /home
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/hd10opt :
Pre Check  : /opt
Post Check : /opt
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/proc :
Pre Check  : /proc
Post Check : /proc
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/livedump :
Pre Check  : /var/adm/ras/livedump
Post Check : /var/adm/ras/livedump
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/admin :
Pre Check  : /admin
Post Check : /admin
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/dev/auditlv :
Pre Check  : /audit
Post Check : /audit
Status=OK
----------------------------------------------------------------
FILESYSTEM_MOUNTS_/ahafs :
Pre Check  : /aha
Post Check : /aha
Status=OK
----------------------------------------------------------------
NETWORK_INTERFACE_en1: :
Pre Check  : IP=192.168.10.11 SubnetMask=0xffffff00
Post Check : IP=192.168.10.11 SubnetMask=0xffffff00
Status=OK
----------------------------------------------------------------
NETWORK_INTERFACE_lo0: :
Pre Check  : IP=127.0.0.1 SubnetMask=0xff000000
Post Check : IP=127.0.0.1 SubnetMask=0xff000000
Status=OK
----------------------------------------------------------------
VG_ONLINE_rootvg :
Pre Check  : online
Post Check : online
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd5 :
Pre Check  : Type=boot State=N/A
Post Check : Type=boot State=N/A
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd6 :
Pre Check  : Type=paging State=N/A
Post Check : Type=paging State=N/A
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd8 :
Pre Check  : Type=jfs2log State=N/A
Post Check : Type=jfs2log State=N/A
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd4 :
Pre Check  : Type=jfs2 State=/
Post Check : Type=jfs2 State=/
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd2 :
Pre Check  : Type=jfs2 State=/usr
Post Check : Type=jfs2 State=/usr
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd9var :
Pre Check  : Type=jfs2 State=/var
Post Check : Type=jfs2 State=/var
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd3 :
Pre Check  : Type=jfs2 State=/tmp
Post Check : Type=jfs2 State=/tmp
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd1 :
Pre Check  : Type=jfs2 State=/home
Post Check : Type=jfs2 State=/home
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_hd10opt :
Pre Check  : Type=jfs2 State=/opt
Post Check : Type=jfs2 State=/opt
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_admin :
Pre Check  : Type=jfs2 State=/admin
Post Check : Type=jfs2 State=/admin
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_livedump :
Pre Check  : Type=jfs2 State=/var/adm/ras/livedump
Post Check : Type=jfs2 State=/var/adm/ras/livedump
Status=OK
----------------------------------------------------------------
LV_STATUS_rootvg_auditlv :
Pre Check  : Type=jfs2 State=/audit
Post Check : Type=jfs2 State=/audit
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_syslogd :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_portmap :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_inetd :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_xntpd :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_biod :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_nfsd :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_rpc.mountd :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_rpc.statd :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_rpc.lockd :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_sshd :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_IBM.DRM :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_IBM.MgmtDomainRM :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_IBM.ServiceRM :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
SERVICE_RUNNING_nimsh :
Pre Check  : active
Post Check : active
Status=OK
----------------------------------------------------------------
POWERHA_CLUSTER_STATUS :
Pre Check  : CommandNotFound
Post Check : CommandNotFound
Status=OK
----------------------------------------------------------------
GPFS_CLUSTER_STATUS :
Pre Check  : CommandNotFound
Post Check : CommandNotFound
Status=OK
----------------------------------------------------------------
root@indjmp01(/tmp)#


No comments:

Post a Comment