shell脚本显示当前主机系统信息

时间:2022-02-17 07:17:43

编写脚本/root/bin/systeminfo.sh,

当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。

vim /root/bin/systeminfo.sh

echo "The hostname is: $(hostname)"

echo "The IPv4 address is: $(ifconfig ens33|grep netmask|tr -s " "|cut -d" " -f3)"

echo "The OS version is: $(cat /etc/redhat-release)"

echo "The kernel version is: $(uname -r)"

echo "The CPU is: $(cat /proc/cpuinfo|grep "model name"|cut -d: -f2)"

echo "The memorysize is: $(echo `cat /proc/meminfo |head -n1|cut -d: -f2|tr -d ' '|grep -o "[0-9]\+"`/1024|bc)MB"

echo "The memorysize is: $[`cat /proc/meminfo |head -n1|cut -d: -f2|tr -d ' '|grep -o "[0-9]\+"`/1024]MB"

echo "The disksize  is: $(fdisk -l |head -n2|tail -1|cut -d: -f2|cut -d, -f1)"

bash /root/bin/systeminfo.sh