Nowadays we are using different versions of Linux systems in our environment.
Few commands are version-specific, we often make mistakes.
Also, we want to gather a few system information like version, hostname, IP address, CPU usage, memory usage, free swap, uptime on login.
Today we will write a script to gather few system details and set it up on logon.
#!/bin/bash
clear
echo -e "\e[1;32m`cat /etc/redhat-release`\e[0m"
echo -e "Hostname: `hostname` \t\t IP Address: `hostname -I`"
echo -e "CPU load: `cat /proc/loadavg | cut -d" " -f1-3`"
echo -e "Uptime: `uptime | cut -d" " -f 4-7 | cut -d"," -f1-2`"
echo -e "Free Memory: `cat /proc/meminfo | grep MemFree | awk {'print int($2/1000)'}` MB \t\t Total Memory: `cat /proc/meminfo | grep MemTotal | awk {'print int($2/1000)'}` MB"
echo -e "Free Swap Memory: `cat /proc/meminfo | grep SwapFree | awk {'print int($2/1000)'}` MB \t Total Swap Memory: `cat /proc/meminfo | grep SwapTotal | awk {'print int($2/1000)'}` MB"
echo -e "Proccess number: `cat /proc/loadavg | cut -d"/" -f2| cut -d" " -f1`\n"
clear
echo -e "\e[1;32m`cat /etc/redhat-release`\e[0m"
echo -e "Hostname: `hostname` \t\t IP Address: `hostname -I`"
echo -e "CPU load: `cat /proc/loadavg | cut -d" " -f1-3`"
echo -e "Uptime: `uptime | cut -d" " -f 4-7 | cut -d"," -f1-2`"
echo -e "Free Memory: `cat /proc/meminfo | grep MemFree | awk {'print int($2/1000)'}` MB \t\t Total Memory: `cat /proc/meminfo | grep MemTotal | awk {'print int($2/1000)'}` MB"
echo -e "Free Swap Memory: `cat /proc/meminfo | grep SwapFree | awk {'print int($2/1000)'}` MB \t Total Swap Memory: `cat /proc/meminfo | grep SwapTotal | awk {'print int($2/1000)'}` MB"
echo -e "Proccess number: `cat /proc/loadavg | cut -d"/" -f2| cut -d" " -f1`\n"
Sample Output:
Copy this script to your home directory and call this script on default login by appending it to .bash_profile
I have named the script as sysinfo.sh