1、脚本编写
cat Firewall_Selinux_status.sh
#!/bin/bash
#=====================================================================#
###Colors
#YELLOW=黄色
YELLOW='\033[0;33m'
#GREEN=绿色
GREEN='\033[32m'
#GULES=红色
GULES='\033[31m'
#YELLOW=黄色
YELLOW='\033[33m'
#BLUE=蓝色
BLUE='\033[34m'
#颜色后缀平原=PLAIN
PLAIN='\033[0m'
#=====================================================================#
Firewalld=`systemctl status firewalld | grep Active | awk '{print $3}' | awk -F '[)(]' '{print $2}'`
Selinux=`getenforce`
CPU_model=`cat /proc/cpuinfo | grep name | cut -d : -f 2 | uniq`
Cores=`cat /proc/cpuinfo|grep "cpu cores"|uniq |awk '{print $4}'`
SN=`dmidecode -t system | grep "Serial Number" | cut -d ":" -f 2| tr -d [:space:]`
OS_version=`cat /etc/redhat-release`
Kernel=`uname -r`
#=====================================================================#
echo "-------------------------------------------------------------------"
#Firewall status
if [ $Firewalld = running ]
then
echo -e "Firewall status : " ${GREEN}${Firewalld}${PLAIN}
else
echo -e "Firewall status : " ${GULES}${Firewalld}${PLAIN}
fi
#Selinux status
if [ $Selinux = Enforcing ]
then
echo -e "Selinux status : " ${GREEN}${Selinux}${PLAIN}
elif [ $Selinux = Permissive ]
then
echo -e "Selinux status : " ${YELLOW}${Selinux}${PLAIN}
else
echo -e "Selinux status : " ${GULES}${Selinux}${PLAIN}
fi
echo "-------------------------------------------------------------------"
echo -e "CPU modle : "${BLUE}$Cores $CPU_model${PLAIN}
echo -e "SN : "${BLUE}$SN${PLAIN}
echo -e "OS version : "${BLUE}$OS_version${PLAIN}
echo -e "Kernel : "${BLUE}$Kernel${PLAIN}
echo "-------------------------------------------------------------------"
#=====================================================================#
2、效果
[root@lxy sh]# sh Firewall_Selinux_status.sh
-------------------------------------------------------------------
Firewall status : dead
Selinux status : Disabled
-------------------------------------------------------------------
CPU modle : 1 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
SN : VMware-564d42d64d21611a-a2e3b83a12da5619
OS version : CentOS Linux release 7.6.1810 (Core)
Kernel : 3.10.0-957.el7.x86_64
-------------------------------------------------------------------