编写脚本 systeminfo.sh,显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
[root@Centos7 ~]# vim systeminfo.sh
#!/bin/bash
#
#********************************************************************
#Author: feifa
#Date: 2021-11-07
#FileName: systeminfo.sh
#Description: The test script
#********************************************************************
BEGINCOLOR="\e[1;35m"
ENDCOLOR="\e[0m"
echo -e "主机名: ${BEGINCOLOR}`hostname`$ENDCOLOR"
echo -e "IP地址: ${BEGINCOLOR}`ifconfig eth0 |grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1`$ENDCOLOR"
echo -e "系统版本: ${BEGINCOLOR}`cat /etc/redhat-release`$ENDCOLOR"
echo -e "内核版本: ${BEGINCOLOR}`uname -r`$ENDCOLOR"
echo -e "CPU型号: ${BEGINCOLOR}`lscpu|grep "Model name" |cut -d: -f2 |tr -s " "`$ENDCOLOR"
echo -e "内存大小: ${BEGINCOLOR}`cat /proc/meminfo |head -n1 |grep -Eo '[0-9]+.*'`$ENDCOLOR"
echo -e "硬盘大小: ${BEGINCOLOR}`lsblk |grep 'vda\>'|grep -Eo '[0-9]+[[:upper:]]'`$ENDCOLOR"
[root@Centos7 ~]# bash systeminfo.sh
主机名: Centos7
IP地址: 10.0.24.9
系统版本: CentOS Linux release 7.6.1810 (Core)
内核版本: 3.10.0-1160.11.1.el7.x86_64
CPU型号: AMD EPYC 7K62 48-Core Processor
内存大小: 3880184 kB
硬盘大小: 80G