root@libin5 shell]# vim shell1.sh
#!/bin/bash
#显示当前主机系统信息,包括:主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小
#********************************************************************
COLOR="\033[1;31m"
END="\033[0m"
echo -e "\033[1;32m-----------------Host systeminfo---------------$END"
echo -e "HOSTNAME: $COLOR`hostname`$END"
echo -e "IPADDR: $COLOR` ifconfig ens160|grep -Eo '([0-9]{1,3}\.){3}[0-9]
{1,3}' |head -n1`$END"
echo -e "OSVERSION: $COLOR`cat /etc/redhat-release`$END"
echo -e "KERNEL: $COLOR`uname -r`$END"
echo -e "CPU: $COLOR`lscpu|grep 'Model name'|tr -s ' '|cut -d : -f2`$END"
echo -e "MEMORY: $COLOR`free -h|grep Mem|tr -s ' ' : |cut -d : -f2`$END"
echo -e "DISK: $COLOR`lsblk |grep '^n' |tr -s ' ' |cut -d " " -f4`$END"
标签:END,COLOR,内存大小,echo,版本,grep,主机名,CPU From: https://www.cnblogs.com/libin-linux/p/16901287.html