运用shell脚本显示主机名字,ipv4地址,操作系统版本,linux内核,cpu型号,内存大小,硬盘大小
[root@localhost ~]# cat systeminfo.sh
#!/bin/bash
hostname=`hostname -s`
IPv4=`ifconfig eth0 | grep -w 'inet' | awk '{print $2}'`
OS=`cat /etc/redhat-release`
linux=`uname -r`
cpu=`lscpu | grep '型号名称' | awk '{print $2,$3,$4,$5,$6,$7.$8}'`
mem=`free -h |free -h | grep Mem | awk '{print $2}'`
disksize=`lsblk | grep '^sd'|awk '{print $1,$4}'|paste -s -d,`
echo -e "Hostname is : ${hostname}"
echo -e "IPV4 adress is : ${IPv4}"
echo -e "OS's version : ${OS}"
echo -e "Kernel version is : ${linux}"
echo -e "CPU version is : $cpu"
echo -e "Memory's size is : ${mem}"
echo -e "Disk size is : ${disksize}"
运行结果
[root@localhost ~]# sh systeminfo.sh
Hostname is : localhost
IPV4 adress is : 192.168.111.132
OS's version : CentOS Linux release 7.6.1810 (Core)
Kernel version is : 3.10.0-957.el7.x86_64
CPU version is : Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
Memory's size is : 1.9G
Disk size is : sda 60G