prechecks - Pro Fresher Jobs

Friday 10 May 2024

prechecks

 #!/bin/bash


# Define the directory and file path for the list of servers

SERVER_DIR="/home/dhruv-root/Downloads"

SERVER_LIST="$SERVER_DIR/servers.txt"


# Create the output file with a date stamp

DATE=$(date "+%m%d%Y")

OUTPUT_FILE="System_Status_${DATE}_DT.txt"


# Start of the script

echo "Starting system status collection..."


# Verify the server list exists

if [[ ! -f "$SERVER_LIST" ]]; then

    echo "Server list file not found in $SERVER_DIR"

    exit 1

fi


# Loop through each server in the list

while read -r server; do

    echo "----------------------" >> "$OUTPUT_FILE"

    echo "Server: $server" >> "$OUTPUT_FILE"

    echo "----------------------" >> "$OUTPUT_FILE"

    # SSH into each server and execute the commands

    ssh "$server" '

        echo "Kernel Information:"

        uname -a

        echo "----------------------"

        echo "System Uptime:"

        uptime

        echo "----------------------"

        echo "Current Date and Time:"

        date

        echo "----------------------"

        echo "System Release Information:"

        cat /etc/*release

        echo "----------------------"

        echo "Mount Points:"

        mount

        echo "----------------------"

        echo "Disk Filesystem Usage:"

        df -hT

        echo "----------------------"

        echo "File System Table Contents:"

        cat /etc/fstab

        echo "----------------------"

        echo "Physical Volume Display:"

        pvdisplay

        echo "----------------------"

        echo "Routing Table:"

        netstat -nr

        echo "----------------------"

        echo "Network Connections (All):"

        netstat -an

        echo "----------------------"

        echo "Network Configuration:"

        ifconfig -a

        ip addr

        echo "----------------------"

        echo "DNS Configuration:"

        cat /etc/resolv.conf

        echo "----------------------"

        echo "Memory Usage:"

        free -m

        echo "----------------------"

        echo "System Activity Report:"

        vmstat

        echo "----------------------"

        echo "Kernel Packages Installed Recently:"

        rpm -qa --last | grep -i kernel

        echo "----------------------"

        echo "Service Configurations (chkconfig):"

        chkconfig --list

        echo "----------------------"

        echo "User Crontab:"

        crontab -l

        echo "----------------------"

        echo "Physical Volumes:"

        pvs

        echo "----------------------"

        echo "Volume Groups:"

        vgs

        echo "----------------------"

        echo "Logical Volumes:"

        lvs

        echo "----------------------"

        echo "IP Addresses containing 'sec':"

        ip a | grep -i sec

        echo "----------------------"

        echo "Failed System Services:"

        systemctl --failed

        echo "----------------------"

        echo "Hosts File:"

        cat /etc/hosts

        echo "----------------------"

        echo "YUM Repositories:"

        yum repolist

        echo "----------------------"

        echo "ZYPPER Repositories:"

        zypper lr

    ' >> "$OUTPUT_FILE"

done < "$SERVER_LIST"


echo "System status collection complete. Data saved to $OUTPUT_FILE"


No comments:

Post a Comment