RHEL 8.2 配置SSH登录显示系统信息

脚本

[root@rhel8-study ~]# vim system-info.sh 
#!/bin/bash
echo -e "-------------------------------System Information----------------------------"
echo -e "Hostname:\t\t"`hostname`
echo -e "uptime:\t\t\t"`uptime | awk '{print $3,$4}' | sed 's/,//'`
echo -e "Manufacturer:\t\t"`cat /sys/class/dmi/id/chassis_vendor`
echo -e "Product Name:\t\t"`cat /sys/class/dmi/id/product_name`
echo -e "Version:\t\t"`cat /sys/class/dmi/id/product_version`
echo -e "Serial Number:\t\t"`cat /sys/class/dmi/id/product_serial`
echo -e "Machine Type:\t\t"`vserver=$(lscpu | grep Hypervisor | wc -l); if [ $vserver -gt 0 ]; then echo "VM"; else echo "Physical"; fi`
echo -e "Operating System:\t"`hostnamectl | grep "Operating System" | cut -d ' ' -f5-`
echo -e "Kernel:\t\t\t"`uname -r`
echo -e "Architecture:\t\t"`arch`
echo -e "Processor Name:\t\t"`awk -F':' '/^model name/ {print $2}' /proc/cpuinfo | uniq | sed -e 's/^[ \t]*//'`
echo -e "Active User:\t\t"`w | cut -d ' ' -f1 | grep -v USER | xargs -n1`
echo -e "System Main IP:\t\t"`hostname -I`
echo ""
echo -e "-------------------------------CPU/Memory Usage------------------------------"
echo -e "Memory Usage:\t"`free | awk '/Mem/{printf("%.2f%"), $3/$2*100}'`
echo -e "Swap Usage:\t"`free | awk '/Swap/{printf("%.2f%"), $3/$2*100}'`
echo -e "CPU Usage:\t"`cat /proc/stat | awk '/cpu/{printf("%.2f%\n"), ($2+$4)*100/($2+$4+$5)}' |  awk '{print $0}' | head -1`
echo ""
echo -e "-------------------------------Disk Usage >80%-------------------------------"
df -Ph | sed s/%//g | awk '{ if($5 > 80) print $0;}'
echo ""
echo -e "-------------------------------For WWN Details-------------------------------"
vserver=$(lscpu | grep Hypervisor | wc -l)
if [ $vserver -gt 0 ]
then
echo "$(hostname) is a VM"
else
cat /sys/class/fc_host/host?/port_name
fi
echo ""
#echo -e "-------------------------------Oracle DB Instances---------------------------"
#if id oracle >/dev/null 2>&1; then
#/bin/ps -ef|grep pmon
#then
#else
#echo "oracle user does not exist on $(hostname)"
#fi
#echo ""
#if (( $(cat /etc/*-release | grep -w "Oracle|Red Hat|CentOS|Fedora" | wc -l) > 0 ))
#then
#echo -e "-------------------------------Package Updates-------------------------------"
#yum updateinfo summary | grep 'Security|Bugfix|Enhancement'
#echo -e "-----------------------------------------------------------------------------"
#else
#echo -e "-------------------------------Package Updates-------------------------------"
#cat /var/lib/update-notifier/updates-available
#echo -e "-----------------------------------------------------------------------------"
#fi
[root@rhel8-study ~]# echo "/root/system-info.sh" >> /root/.bash_profile #脚本文件的路径加到 .bash_profile 文件末尾
[root@rhel8-study ~]# source /root/.bash_profile # 生效

效果预览

Last login: Tue Jul 21 04:11:35 2020 from 203.0.113.1
-------------------------------System Information----------------------------
Hostname:               rhel8-study
uptime:                 7 min
Manufacturer:           DELL
Product Name:           R420
Version:                DELL R420
Serial Number:          8a8hdl81
Machine Type:           Physical
Operating System:       Red Hat Enterprise Linux 8.2 (Ootpa)
Kernel:                 4.18.0-193.el8.x86_64
Architecture:           x86_64
Processor Name:         16  Intel(R) Xeon(R) CPU E5620  @ 2.40GHz
Active User:            root
System Main IP:         203.0.113.11

-------------------------------CPU/Memory Usage------------------------------
Memory Usage:   5.70%
Swap Usage:     0.00%
CPU Usage:      0.78%

-------------------------------Disk Usage >80%-------------------------------
Filesystem             Size  Used Avail Use Mounted on

-------------------------------For WWN Details-------------------------------
rhel8-study is a VM
上一篇
下一篇