脚本内容

#!/bin/bash
RED="\E[1;31m"
GREEN="echo -e \E[1;32m"
END="\E[0m"
HOSTNAME=$(hostname)
IP=`ifconfig | egrep -o "([0-9]{1,3}\.){3}[0-9]{1,3}" | head -n1`
OS=`cat /etc/redhat-release`
KERNEL=$(uname -a | cut -d " " -f3)
CPU=`lscpu | grep "Model name" | tr -s " " | cut -d : -f2`
MEM=`lsmem | grep "Total online memory" | egrep -o [0-9]+.`
DISK=`lsblk | egrep '^sd'|tr -s " " | cut -d " " -f4`
$GREEN----------------------Host systeminfo--------------------$END
echo -e "主机名:" $HOSTNAME
echo -e "IP地址:" $IP
echo -e "系统版本:" $OS
echo -e "内核版本:" $KERNEL
echo -e "CPU型号:" $CPU
echo -e "内存大小:" $MEM
echo -e "磁盘空间大小:" $DISK
$GREEN---------------------------------------------------------$END

shell脚本编程-获取系统信息_bash