Pages

Solaris Server pre & post validation script run from remote server

Make sure you can SSH into these hosts passwordlessly (using SSH keys).
Example:
Jump server : [root@inddcpjmp01 solaris]#
./solaris_pre_check.sh indsuntst01
./solaris_post_check.sh indsuntst01

1. Remote Pre Check Script (solaris_pre_check.sh)
[root@inddcpjmp01 solaris]# cat solaris_pre_check.sh
#!/bin/bash
# =============================================================
# Solaris Pre-Reboot Validation Script
# Author: Tasleem Ahmed Khan
# Version: 1.1
# Description: Collects pre-reboot system details in structured
#              key=value format for post-reboot comparison.
# =============================================================

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

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

for server in "$@"; do
    outfile="${log_dir}/${server}_pre_${timestamp}.log"
    echo "Collecting pre-reboot data for $server..."

    ssh -o ConnectTimeout=10 "$server" bash <<'EOF' > "$outfile" 2>&1
# ----------------- SYSTEM INFORMATION -----------------
echo "HOSTNAME=$(hostname)"
echo "OS_VERSION=$(cat /etc/release | head -1)"
echo "KERNEL=$(uname -r)"
echo "ARCH=$(uname -p)"
echo "UPTIME=$(uptime | awk -F'up' '{print $2}' | sed 's/ //g')"

# ----------------- CPU -----------------
echo "CPU_CORES=$(psrinfo | wc -l)"
echo "CPU_MODEL=$(psrinfo -pv | head -1)"

# ----------------- MEMORY -----------------
MEM_TOTAL=$(prtconf | grep "Memory size" | awk '{print $3}')
FREE_PAGES=$(vmstat 1 2 | tail -1 | awk '{print $5}')
PAGE_SIZE=$(pagesize)
MEM_FREE=$(echo "$FREE_PAGES * $PAGE_SIZE / 1024 / 1024" | bc)
echo "MEM_TOTAL_MB=$MEM_TOTAL"
echo "MEM_FREE_MB=$MEM_FREE"

# ----------------- DISK -----------------
DISK_TOTAL=$(df -k | awk 'NR>1 {sum+=$2} END {print sum/1024/1024}')
DISK_USED=$(df -k | awk 'NR>1 {sum+=$3} END {print sum/1024/1024}')
DISK_FREE=$(df -k | awk 'NR>1 {sum+=$4} END {print sum/1024/1024}')
echo "DISK_TOTAL_GB=$DISK_TOTAL"
echo "DISK_USED_GB=$DISK_USED"
echo "DISK_FREE_GB=$DISK_FREE"

# ----------------- FILESYSTEMS & MOUNTS -----------------
fs_mounts=$(mount | awk '{print $3":"$5}' | paste -sd,)
echo "FILESYSTEM_MOUNTS=$fs_mounts"

# ----------------- ZFS POOLS -----------------
if command -v zpool >/dev/null 2>&1; then
    zpool_status=$(zpool list -H -o name,health | awk '{print $1":"$2}' | paste -sd,)
    echo "ZFS_POOL_STATUS=$zpool_status"
else
    echo "ZFS_POOL_STATUS=NA"
fi

# ----------------- NFS / NAS MOUNTS -----------------
nfs_mounts=$(mount | grep -i 'nfs|nas' | awk '{print $3}' | paste -sd,)
echo "NFS_MOUNTS=$nfs_mounts"

# ----------------- SERVICES -----------------
services=$(svcs -Ho FMRI | paste -sd,)
echo "SERVICES_RUNNING=$services"

# ----------------- OPEN PORTS -----------------
ports=$(netstat -an | grep LISTEN | awk '{print $4}' | awk -F"." '{print $NF}' | paste -sd,)
echo "OPEN_PORTS=$ports"

# ----------------- PROCESSES -----------------
proc_count=$(ps -ef | wc -l)
echo "PROCESS_COUNT=$proc_count"

# ----------------- LOAD AVERAGE -----------------
load=$(uptime | awk -F'load average:' '{print $2}' | sed 's/ //g')
echo "LOAD_AVG=$load"

# ----------------- OS PATCHES -----------------
echo "OS_PATCHES=$(showrev -p | head -20 | paste -sd,)"
EOF

    echo "Pre-reboot data collected for $server"
    echo "Log saved at: $outfile"
    echo "------------------------------------------------------------"
done

[root@inddcpjmp01 solaris]#

1. Remote Post Check Script (solaris_post_check.sh)
[root@inddcpjmp01 solaris]# cat solaris_post_check.sh
#!/bin/bash
# =============================================================
# Solaris Post-Reboot Validation Script
# Author: Tasleem Ahmed Khan
# Version: 1.1
# Description: Collects post-reboot system details and compares
#              with pre-reboot baseline.
# =============================================================

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

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

for server in "$@"; do
    # Find latest pre-reboot log
    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 for $server. Run pre-check first!"
        continue
    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 -o ConnectTimeout=10 "$server" bash <<'EOF' > "$post_file" 2>&1
# ----------------- SYSTEM INFORMATION -----------------
echo "HOSTNAME=$(hostname)"
echo "OS_VERSION=$(cat /etc/release | head -1)"
echo "KERNEL=$(uname -r)"
echo "ARCH=$(uname -p)"
echo "UPTIME=$(uptime | awk -F'up' '{print $2}' | sed 's/ //g')"

# ----------------- CPU -----------------
echo "CPU_CORES=$(psrinfo | wc -l)"
echo "CPU_MODEL=$(psrinfo -pv | head -1)"

# ----------------- MEMORY -----------------
MEM_TOTAL=$(prtconf | grep "Memory size" | awk '{print $3}')
FREE_PAGES=$(vmstat 1 2 | tail -1 | awk '{print $5}')
PAGE_SIZE=$(pagesize)
MEM_FREE=$(echo "$FREE_PAGES * $PAGE_SIZE / 1024 / 1024" | bc)
echo "MEM_TOTAL_MB=$MEM_TOTAL"
echo "MEM_FREE_MB=$MEM_FREE"

# ----------------- DISK -----------------
DISK_TOTAL=$(df -k | awk 'NR>1 {sum+=$2} END {print sum/1024/1024}')
DISK_USED=$(df -k | awk 'NR>1 {sum+=$3} END {print sum/1024/1024}')
DISK_FREE=$(df -k | awk 'NR>1 {sum+=$4} END {print sum/1024/1024}')
echo "DISK_TOTAL_GB=$DISK_TOTAL"
echo "DISK_USED_GB=$DISK_USED"
echo "DISK_FREE_GB=$DISK_FREE"

# ----------------- FILESYSTEMS & MOUNTS -----------------
fs_mounts=$(mount | awk '{print $3":"$5}' | paste -sd,)
echo "FILESYSTEM_MOUNTS=$fs_mounts"

# ----------------- ZFS POOLS -----------------
if command -v zpool >/dev/null 2>&1; then
    zpool_status=$(zpool list -H -o name,health | awk '{print $1":"$2}' | paste -sd,)
    echo "ZFS_POOL_STATUS=$zpool_status"
else
    echo "ZFS_POOL_STATUS=NA"
fi

# ----------------- NFS / NAS MOUNTS -----------------
nfs_mounts=$(mount | grep -i 'nfs|nas' | awk '{print $3}' | paste -sd,)
echo "NFS_MOUNTS=$nfs_mounts"

# ----------------- SERVICES -----------------
services=$(svcs -Ho FMRI | paste -sd,)
echo "SERVICES_RUNNING=$services"

# ----------------- OPEN PORTS -----------------
ports=$(netstat -an | grep LISTEN | awk '{print $4}' | awk -F"." '{print $NF}' | paste -sd,)
echo "OPEN_PORTS=$ports"

# ----------------- PROCESSES -----------------
proc_count=$(ps -ef | wc -l)
echo "PROCESS_COUNT=$proc_count"

# ----------------- LOAD AVERAGE -----------------
load=$(uptime | awk -F'load average:' '{print $2}' | sed 's/ //g')
echo "LOAD_AVG=$load"

# ----------------- OS PATCHES -----------------
echo "OS_PATCHES=$(showrev -p | head -20 | paste -sd,)"
EOF

    # ----------------- Comparison -----------------
    echo "==================== PRE vs POST COMPARISON ====================" > "$compare_file"
    while IFS='=' read -r key pre_value; do
        post_value=$(grep "^$key=" "$post_file" | cut -d= -f2-)
        if [ "$pre_value" = "$post_value" ]; then
            status="OK"
        else
            status="MISMATCH"
        fi
        echo "$key : Pre=$pre_value | Post=$post_value | Status=$status" >> "$compare_file"
    done < "$pre_file"

    echo "Post-reboot check completed for $server"
    echo "Post log: $post_file"
    echo "Comparison report: $compare_file"
    echo "------------------------------------------------------------"
done

[root@inddcpjmp01 solaris]#

Example Output:
[root@inddcpjmp01 solaris]# cat logs/indsuntst01_comparison_20251026_135247.log
==================== PRE vs POST COMPARISON ====================
HOSTNAME : Pre=indsuntst01 | Post=indsuntst01 | Status=OK
OS_VERSION : Pre=                             Oracle Solaris 11.4 X86 | Post=                             Oracle Solaris 11.4 X86 | Status=OK
KERNEL : Pre=5.11 | Post=5.11 | Status=OK
ARCH : Pre=i386 | Post=i386 | Status=OK
UPTIME : Pre=p1:14,1 | Post=p1:15,1 | Status=MISMATCH
CPU_CORES : Pre=2 | Post=2 | Status=OK
CPU_MODEL : Pre=The physical processor has 2 virtual processors (0-1) | Post=The physical processor has 2 virtual processors (0-1) | Status=OK
MEM_TOTAL_MB : Pre=4096 | Post=4096 | Status=OK
MEM_FREE_MB : Pre=10325 | Post=10331 | Status=MISMATCH
DISK_TOTAL_GB : Pre=254.52 | Post=254.52 | Status=OK
DISK_USED_GB : Pre=5.51882 | Post=5.51882 | Status=OK
DISK_FREE_GB : Pre=178.836 | Post=178.836 | Status=OK
FILESYSTEM_MOUNTS : Pre= | Post= | Status=OK
ZFS_POOL_STATUS : Pre= | Post= | Status=OK
NFS_MOUNTS : Pre= | Post= | Status=OK
SERVICES_RUNNING : Pre= | Post= | Status=OK
OPEN_PORTS : Pre= | Post= | Status=OK
PROCESS_COUNT : Pre=80 | Post=80 | Status=OK
LOAD_AVG : Pre=oadaverage:0.01,0.01,0.01 | Post=oadaverage:0.02,0.01,0.01 | Status=MISMATCH
bash: line 61: showrev: command not found : Pre= | Post= | Status=OK
OS_PATCHES : Pre= | Post= | Status=OK
[root@inddcpjmp01 solaris]#



No comments:

Post a Comment