shell script to gather Server information (after login):

It will shows the server information when login.

# create a file 'server_info.sh'
# copy and paste the below code.
=========================================

#!/bin/bash
wait ()
{
echo -en  "Gathering server information..."
a=1
while [ $a -le 20 ]
do
echo -ne "."
sleep .1
a=`expr $a + 1`
done
}

pause ()
{
   echo "Press [ Enter ] to continue..."
   read -p "$*"
}

raw_mem=$(cat /proc/meminfo  | grep 'MemTotal\|MemFree\|^Cached' | awk '{print $2}')
me=$(echo $raw_mem |awk '{print $1}')
tot=$((me/1024))
mef=$(echo $raw_mem |awk '{print $2}')
fre=$((mef/1024))
mec=$(echo $raw_mem |awk '{print $3}')
cac=$((mec/1024))
use=$((tot-fre))
ho=$(hostname)
os=$(cat /etc/redhat-release)
ker=$(uname -sr)
curc=$(who | awk '{print $1}'| wc -l)
lo=$(uptime| cut -f3,4,5 -d',')
wait
clear

echo -e "\nSYSTEM INFORMATION!"
echo -e "==================="
echo -e "\nOS info:" $os
echo -e "kernel name/release:" $ker
echo -e "\nMEMORY STATUS:"
echo -e "=============="
echo -e 'Total Memory:' $tot 'MB'
echo -e 'Memory In Use:' $use 'MB'
echo -e 'Free Memory:' $fre 'MB'
echo -e 'Cached Memory:' $cac 'MB'
echo -e '\n=> Hostname:' $ho
echo -e '=> Currnet users:' $curc
echo -e '=> Server' $lo '\n'
pause
clear

========================================================

# echo "/bin/bash /path/to/server_info.sh" >> /root/.bashrc

# from next login, you can find the server_info.sh's work....



Press [ Enter ] to continue...

!!!!!!.....

Comments

Popular posts from this blog

Resolved: DOCKER: Error response from daemon: Could not attach to network / rpc error: code = 7 desc = network not manually attachable.

yum failed 6 times. Cannot continue!

How to echo colored text in linux shell script: