You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shell-project/os/status.sh

56 lines
1.5 KiB

#!/bin/bash
# 定义颜色
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
# 检测网络连接的函数
function network() {
if ping -c 2 www.baidu.com &> /dev/null; then
printf "[ ${GREEN}OK${NC} ]\n"
else
printf "[ ${RED}Failed${NC} ]\n"
fi
}
# 检测SSH服务是否开启的函数
function ssh_service() {
if systemctl status sshd &> /dev/null; then
printf "[ ${GREEN}OK${NC} ]\n"
else
printf "[ ${RED}Failed${NC} ]\n"
fi
}
# 检测防火墙是否开启的函数
function firewall() {
if systemctl status firewalld &> /dev/null; then
printf "[ ${GREEN}OK${NC} ]\n"
else
printf "[ ${RED}Failed${NC} ]\n"
fi
}
# 检测SELinux状态的函数
function selinux() {
se_status=$(getenforce)
if [ "$se_status" = "Enforcing" ] || [ "$se_status" = "Permissive" ]; then
printf "[ ${GREEN}OK${NC} ]\n"
else
printf "[ ${RED}Failed${NC} ]\n"
fi
}
# 执行函数并直接使用其输出
clear
echo "===============================系统检测中=============================="
echo "======================================================================="
echo "当前时间: [ $(date '+%F %X') ]"
echo "网络地址: [ $(ip -4 a show dev ens33 | awk 'NR==2{print $2}') ]"
echo -n "网络连接: "; network
echo -n "远程连接: "; ssh_service
echo -n "防火墙: "; firewall
echo -n "SELinux: "; selinux
echo "======================================================================="