当前位置: 首页 > news >正文

分享:一键自动化巡检服务器

在服务器上编写下列脚本check.sh

#!/bin/bash
# 综合系统巡检工具
# 功能整合:安全检测、性能监控、环境变量检查、句柄分析、服务状态监控等
# 使用前请以root权限运行,建议定期执行(如每日/每周)# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # 无颜色# 检查是否以root权限运行
if [ "$(id -u)" -ne 0 ]; thenecho -e "${RED}错误:此脚本需要以root权限运行,请使用sudo或切换到root用户${NC}"exit 1
fi# 检查必要工具是否安装
check_dependencies() {local deps="sysstat iotop net-tools bc lsof"local missing=""for dep in $deps; doif ! command -v $dep &> /dev/null && ! dpkg -s $dep &> /dev/null && ! rpm -q $dep &> /dev/null; thenmissing="$missing $dep"fidoneif [ -n "$missing" ]; thenecho -e "${YELLOW}检测到缺少必要工具,正在尝试安装...${NC}"if command -v apt &> /dev/null; thenapt update -y &> /dev/nullapt install -y $missing &> /dev/nullelif command -v yum &> /dev/null; thenyum install -y $missing &> /dev/nullelseecho -e "${RED}无法自动安装依赖,请手动安装: $missing${NC}"exit 1fifi
}# 初始化巡检报告
REPORT_FILE="system_inspection_$(date +%Y%m%d_%H%M%S).log"
echo -e "系统综合巡检报告 - $(date)\n" > $REPORT_FILE# 添加内容到报告
add_to_report() {echo -e "$1" >> $REPORT_FILE
}# 显示开始信息
echo -e "${YELLOW}===== 系统综合巡检工具 ====="
echo "巡检时间: $(date)"
echo "报告将保存至: $REPORT_FILE"
echo "正在检查依赖工具..."
check_dependencies
echo "=================================${NC}"# 1. 系统基本信息
echo -e "\n${BLUE}1. 系统基本信息${NC}"
add_to_report "1. 系统基本信息"os_info=$(cat /etc/os-release | grep PRETTY_NAME | cut -d= -f2 | tr -d '"' 2>/dev/null || echo "未知")
kernel_version=$(uname -r)
hostname=$(hostname)
uptime=$(uptime | awk '{print $3 " " $4}' | sed 's/,//')
ip_address=$(hostname -I | awk '{print $1}')echo -e "  系统版本: $os_info"
echo -e "  内核版本: $kernel_version"
echo -e "  主机名: $hostname"
echo -e "  IP地址: $ip_address"
echo -e "  运行时间: $uptime"
add_to_report "  系统版本: $os_info"
add_to_report "  内核版本: $kernel_version"
add_to_report "  主机名: $hostname"
add_to_report "  IP地址: $ip_address"
add_to_report "  运行时间: $uptime"# 2. 环境变量安全检测
echo -e "\n${BLUE}2. 环境变量安全检测${NC}"
add_to_report "\n2. 环境变量安全检测"# 2.1 PATH环境变量分析
echo -e "  PATH环境变量分析..."
path_var=$PATH
IFS=':' read -ra path_array <<< "$path_var"
echo "    PATH包含 ${#path_array[@]} 个路径"
add_to_report "    PATH包含 ${#path_array[@]} 个路径"dangerous_paths="/ /root /tmp /var/tmp /dev/shm"
for path in "${path_array[@]}"; dofor dangerous in $dangerous_paths; doif [ "$path" = "$dangerous" ]; thenecho -e "${RED}    危险路径: $path (包含在PATH中)${NC}"add_to_report "    ${RED}危险路径: $path (包含在PATH中)${NC}"fidoneif [ -d "$path" ] && [ -w "$path" ] && ! ls -ld "$path" | grep -qE '^drwxr-xr-x'; thenecho -e "${YELLOW}    可写路径: $path (存在非授权写入风险)${NC}"add_to_report "    ${YELLOW}可写路径: $path (存在非授权写入风险)${NC}"fi
done# 2.2 敏感环境变量扫描
echo -e "\n  敏感环境变量扫描..."
sensitive_vars="PASSWORD SECRET KEY TOKEN CREDENTIAL PASS DB_PASS"
found_sensitive=0
for var in $sensitive_vars; domatches=$(env | grep -i "$var" | grep -v -E '^SHLVL=|^PWD=|^_=|^LS_COLORS=')if [ -n "$matches" ]; thenfound_sensitive=1echo -e "${YELLOW}    潜在敏感变量:${NC}"echo "$matches" | awk -F= '{print "      " $1 "=***(内容已隐藏)***"}'add_to_report "    ${YELLOW}潜在敏感变量: $var${NC}"fi
done
if [ $found_sensitive -eq 0 ]; thenecho -e "${GREEN}    未发现明显敏感环境变量${NC}"add_to_report "    ${GREEN}未发现明显敏感环境变量${NC}"
fi# 2.3 环境配置文件检查
echo -e "\n  环境配置文件权限检查..."
env_files="/etc/profile /etc/bashrc ~/.bashrc ~/.bash_profile"
for file in $env_files; doexpanded_file=$(eval echo "$file")if [ -f "$expanded_file" ]; thenperms=$(stat -c "%a" "$expanded_file" 2>/dev/null || echo "未知")if [ "$perms" -gt 644 ] 2>/dev/null; thenecho -e "${RED}    不安全权限: $expanded_file (权限$perms,建议≤644)${NC}"add_to_report "    ${RED}不安全权限: $expanded_file (权限$perms,建议≤644)${NC}"elseecho -e "    安全权限: $expanded_file (权限$perms)"add_to_report "    安全权限: $expanded_file (权限$perms)"fifi
done# 3. 系统句柄数分析
echo -e "\n${BLUE}3. 系统句柄数分析${NC}"
add_to_report "\n3. 系统句柄数分析"# 3.1 句柄限制配置
echo -e "  句柄限制配置..."
sys_max_open=$(cat /proc/sys/fs/file-max 2>/dev/null || echo "0")
sys_current_max=$(cat /proc/sys/fs/file-nr 2>/dev/null | awk '{print $1}' || echo "0")
sys_available=$((sys_max_open - sys_current_max))echo "    系统级最大句柄数: $sys_max_open"
echo "    当前系统已使用句柄: $sys_current_max"
echo "    系统句柄剩余可用: $sys_available"
add_to_report "    系统级最大句柄数: $sys_max_open"
add_to_report "    当前系统已使用句柄: $sys_current_max"
add_to_report "    系统句柄剩余可用: $sys_available"user_soft=$(ulimit -Sn 2>/dev/null || echo "未知")
user_hard=$(ulimit -Hn 2>/dev/null || echo "未知")
echo "    用户级句柄限制(软): $user_soft"
echo "    用户级句柄限制(硬): $user_hard"
add_to_report "    用户级句柄限制(软): $user_soft"
add_to_report "    用户级句柄限制(硬): $user_hard"if command -v bc &> /dev/null && [ "$sys_max_open" -gt 0 ]; thenusage_rate=$(echo "scale=2; $sys_current_max / $sys_max_open * 100" | bc)echo "    系统句柄整体使用率: $usage_rate%"add_to_report "    系统句柄整体使用率: $usage_rate%"if (( $(echo "$usage_rate > 80" | bc -l) )); thenecho -e "${RED}    警告: 系统句柄使用率超过80%,可能面临耗尽风险${NC}"add_to_report "    ${RED}警告: 系统句柄使用率超过80%,可能面临耗尽风险${NC}"fi
elseecho "    系统句柄整体使用率: 无法计算(bc未安装或数据无效)"add_to_report "    系统句柄整体使用率: 无法计算(bc未安装或数据无效)"
fi# 3.2 进程句柄TOP分析
echo -e "\n  句柄使用TOP 10进程..."
if command -v lsof &> /dev/null; thenecho "    排名  PID    句柄数  进程名"echo "    -------------------------"add_to_report "    进程句柄使用TOP 10:"add_to_report "    排名  PID    句柄数  进程名"add_to_report "    -------------------------"rank=0lsof -n 2>/dev/null | awk '{print $2}' | sort | uniq -c | sort -nr | head -10 | while read count pid; doif [ -n "$pid" ] && [ "$pid" -gt 0 ] 2>/dev/null; thencmd=$(ps -p $pid -o comm= 2>/dev/null || echo "未知")rank=$((rank+1))printf "    %-5d %-6d %-7d %s\n" $rank $pid $count "$cmd"add_to_report "    $rank    $pid    $count    $cmd"fidone
elseecho -e "${YELLOW}    lsof未安装,无法分析进程句柄使用情况${NC}"add_to_report "    ${YELLOW}lsof未安装,无法分析进程句柄使用情况${NC}"
fi# 4. 系统性能深度检测
echo -e "\n${BLUE}4. 系统性能检测${NC}"
add_to_report "\n4. 系统性能检测"# 4.1 CPU性能分析
echo -e "  CPU性能分析..."
cpu_cores=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || echo "未知")
cpu_model=$(grep -m1 'model name' /proc/cpuinfo 2>/dev/null | cut -d: -f2 | sed -e 's/^ *//' || echo "未知")echo "    CPU型号: $cpu_model"
echo "    CPU核心数: $cpu_cores"
add_to_report "    CPU型号: $cpu_model"
add_to_report "    CPU核心数: $cpu_cores"if command -v mpstat &> /dev/null; thencpu_usage=$(mpstat 5 1 2>/dev/null | awk '/Average/ {printf "%.2f", 100 - $13}' || echo "未知")echo "    CPU平均使用率(5秒): $cpu_usage%"add_to_report "    CPU平均使用率(5秒): $cpu_usage%"if command -v bc &> /dev/null && [ "$cpu_usage" != "未知" ]; thenif (( $(echo "$cpu_usage > 80" | bc -l) )); thenecho -e "${RED}    警告: CPU使用率超过80%${NC}"add_to_report "    ${RED}警告: CPU使用率超过80%${NC}"fifi
elseecho "    CPU平均使用率: mpstat未安装,无法获取"add_to_report "    CPU平均使用率: mpstat未安装,无法获取"
fiecho -e "\n    CPU占用TOP5进程:"
ps -eo %cpu,pid,user,comm --sort=-%cpu 2>/dev/null | head -6 | awk 'NR==1 {print "      " $0} NR>1 {printf "      %.2f%%  %-6d %-8s %s\n", $1, $2, $3, $4}'
add_to_report "    CPU占用TOP5进程:"
ps -eo %cpu,pid,user,comm --sort=-%cpu 2>/dev/null | head -6 >> $REPORT_FILE# 4.2 内存性能分析
echo -e "\n  内存性能分析..."
mem_total=$(free -h 2>/dev/null | grep Mem | awk '{print $2}' || echo "未知")
mem_used=$(free -h 2>/dev/null | grep Mem | awk '{print $3}' || echo "未知")
mem_free=$(free -h 2>/dev/null | grep Mem | awk '{print $4}' || echo "未知")
mem_available=$(free -h 2>/dev/null | grep Mem | awk '{print $7}' || echo "未知")if command -v free &> /dev/null; thenmem_used_percent=$(free 2>/dev/null | grep Mem | awk '{printf "%.2f", $3/$2*100}' || echo "未知")
elsemem_used_percent="未知"
fiecho "    总内存: $mem_total"
echo "    已使用: $mem_used ($mem_used_percent%)"
echo "    空闲内存: $mem_free"
echo "    可用内存: $mem_available"
add_to_report "    总内存: $mem_total"
add_to_report "    已使用: $mem_used ($mem_used_percent%)"
add_to_report "    空闲内存: $mem_free"
add_to_report "    可用内存: $mem_available"if command -v bc &> /dev/null && [ "$mem_used_percent" != "未知" ]; thenif (( $(echo "$mem_used_percent > 85" | bc -l) )); thenecho -e "${RED}    警告: 内存使用率超过85%${NC}"add_to_report "    ${RED}警告: 内存使用率超过85%${NC}"fi
fiecho -e "\n    内存占用TOP5进程:"
ps -eo %mem,rss,pid,user,comm --sort=-%mem 2>/dev/null | head -6 | awk 'NR==1 {print "      " $0} NR>1 {printf "      %.2f%%  %-6s %-6d %-8s %s\n", $1, $2"K", $3, $4, $5}'
add_to_report "    内存占用TOP5进程:"
ps -eo %mem,rss,pid,user,comm --sort=-%mem 2>/dev/null | head -6 >> $REPORT_FILE# 4.3 磁盘性能分析
echo -e "\n  磁盘性能分析..."
echo "    磁盘分区使用率:"
add_to_report "    磁盘分区使用率:"
df -h 2>/dev/null | grep -vE 'tmpfs|loop|udev' | awk 'NR>1 {print $0}' | while read line; doecho "    $line"add_to_report "    $line"usage=$(echo $line | awk '{print $5}' | sed 's/%//' 2>/dev/null || echo "0")if [ "$usage" -gt 85 ] 2>/dev/null; thenmount_point=$(echo $line | awk '{print $6}')echo -e "${RED}    警告: $mount_point 分区使用率超过85%${NC}"add_to_report "    ${RED}警告: $mount_point 分区使用率超过85%${NC}"fi
doneecho -e "\n    磁盘I/O性能(5秒采样):"
if command -v iostat &> /dev/null; theniostat -x 5 1 2>/dev/null | awk 'NR>3 {printf "      %-8s  读速: %-6sB/s  写速: %-6sB/s  利用率: %s\n", $1, $6*512, $7*512, $14 "%"}'add_to_report "    磁盘I/O性能(5秒采样):"iostat -x 5 1 2>/dev/null | awk 'NR>3' >> $REPORT_FILE
elseecho -e "${YELLOW}    iostat未安装,无法获取磁盘I/O性能${NC}"add_to_report "    ${YELLOW}iostat未安装,无法获取磁盘I/O性能${NC}"
fi# 4.4 网络性能分析
echo -e "\n  网络性能分析..."
echo "    网络接口流量(5秒采样):"
if command -v sar &> /dev/null; thensar -n DEV 5 1 2>/dev/null | awk 'NR>2 {if($6+$7>0) printf "      %-6s  接收: %-6sB/s  发送: %-6sB/s  总流量: %-6sB/s\n", $2, $6, $7, $6+$7}'add_to_report "    网络接口流量(5秒采样):"sar -n DEV 5 1 2>/dev/null | awk 'NR>2' >> $REPORT_FILE
elseecho -e "${YELLOW}    sar未安装,无法获取网络流量信息${NC}"add_to_report "    ${YELLOW}sar未安装,无法获取网络流量信息${NC}"
fiecho -e "\n    网络连接状态分布:"
if command -v netstat &> /dev/null; thennetstat -ant 2>/dev/null | awk '/^tcp/ {++S[$NF]} END {for(a in S) print "      " a ": " S[a] " 个连接"}' || echo "      无法获取网络连接信息"add_to_report "    网络连接状态分布:"netstat -ant 2>/dev/null | awk '/^tcp/ {++S[$NF]} END {for(a in S) print "      " a ": " S[a] " 个连接"}' >> $REPORT_FILE 2>/dev/null || add_to_report "      无法获取网络连接信息"
elseecho -e "${YELLOW}    netstat未安装,无法获取网络连接信息${NC}"add_to_report "    ${YELLOW}netstat未安装,无法获取网络连接信息${NC}"
fi# 5. 系统安全检测
echo -e "\n${BLUE}5. 系统安全检测${NC}"
add_to_report "\n5. 系统安全检测"# 5.1 用户安全检查
echo -e "  用户安全检查..."
empty_passwords=$(awk -F: '($2 == "" && $1 != "root") {print $1}' /etc/shadow 2>/dev/null || echo "")
if [ -z "$empty_passwords" ]; thenecho -e "${GREEN}    未发现空密码账户${NC}"add_to_report "    ${GREEN}未发现空密码账户${NC}"
elseecho -e "${RED}    发现以下空密码账户: $empty_passwords${NC}"add_to_report "    ${RED}发现以下空密码账户: $empty_passwords${NC}"
fiprivileged_users=$(awk -F: '($3 == 0 && $1 != "root") {print $1}' /etc/passwd 2>/dev/null || echo "")
if [ -z "$privileged_users" ]; thenecho -e "${GREEN}    未发现除root外的特权用户${NC}"add_to_report "    ${GREEN}未发现除root外的特权用户${NC}"
elseecho -e "${RED}    发现以下非root特权用户: $privileged_users${NC}"add_to_report "    ${RED}发现以下非root特权用户: $privileged_users${NC}"
fi# 5.2 关键文件权限检查
echo -e "\n  关键文件权限检查..."
critical_files="/etc/passwd /etc/shadow /etc/sudoers /etc/group /etc/hosts /etc/resolv.conf"for file in $critical_files; doif [ -f "$file" ]; thenperms=$(stat -c "%a" "$file" 2>/dev/null || echo "未知")case $file in"/etc/shadow")if [ "$perms" -ne 400 ] 2>/dev/null; thenecho -e "${RED}    不安全的权限: $file 权限为 $perms (应设置为400)${NC}"add_to_report "    ${RED}不安全的权限: $file 权限为 $perms (应设置为400)${NC}"elseecho -e "${GREEN}    安全的权限: $file 权限为 $perms${NC}"add_to_report "    ${GREEN}安全的权限: $file 权限为 $perms${NC}"fi;;"/etc/sudoers")if [ "$perms" -ne 440 ] 2>/dev/null; thenecho -e "${RED}    不安全的权限: $file 权限为 $perms (应设置为440)${NC}"add_to_report "    ${RED}不安全的权限: $file 权限为 $perms (应设置为440)${NC}"elseecho -e "${GREEN}    安全的权限: $file 权限为 $perms${NC}"add_to_report "    ${GREEN}安全的权限: $file 权限为 $perms${NC}"fi;;*)if [ "$perms" -gt 644 ] 2>/dev/null; thenecho -e "${RED}    不安全的权限: $file 权限为 $perms (建议不高于644)${NC}"add_to_report "    ${RED}不安全的权限: $file 权限为 $perms (建议不高于644)${NC}"elseecho -e "${GREEN}    安全的权限: $file 权限为 $perms${NC}"add_to_report "    ${GREEN}安全的权限: $file 权限为 $perms${NC}"fi;;esacelseecho -e "${YELLOW}    警告: 未找到文件 $file${NC}"add_to_report "    ${YELLOW}警告: 未找到文件 $file${NC}"fi
done# 5.3 SSH与防火墙检查
echo -e "\n  远程访问与防火墙检查..."
ssh_config="/etc/ssh/sshd_config"
if [ -f "$ssh_config" ]; thenroot_login=$(grep -E '^PermitRootLogin' $ssh_config 2>/dev/null | awk '{print $2}' | head -1)if [ "$root_login" = "no" ]; thenecho -e "${GREEN}    SSH已禁用root直接登录${NC}"add_to_report "    ${GREEN}SSH已禁用root直接登录${NC}"elseecho -e "${RED}    SSH允许root直接登录 (建议设置为PermitRootLogin no)${NC}"add_to_report "    ${RED}SSH允许root直接登录 (建议设置为PermitRootLogin no)${NC}"fi
fiif command -v ufw &> /dev/null; thenufw_status=$(ufw status 2>/dev/null | grep "Status" | awk '{print $2}')if [ "$ufw_status" = "active" ]; thenecho -e "${GREEN}    UFW防火墙已激活${NC}"add_to_report "    ${GREEN}UFW防火墙已激活${NC}"elseecho -e "${RED}    UFW防火墙未激活${NC}"add_to_report "    ${RED}UFW防火墙未激活${NC}"fi
elif command -v firewalld &> /dev/null; thenfirewalld_status=$(systemctl is-active firewalld 2>/dev/null)if [ "$firewalld_status" = "active" ]; thenecho -e "${GREEN}    firewalld防火墙已激活${NC}"add_to_report "    ${GREEN}firewalld防火墙已激活${NC}"elseecho -e "${RED}    firewalld防火墙未激活${NC}"add_to_report "    ${RED}firewalld防火墙未激活${NC}"fi
elseecho -e "${YELLOW}    未检测到UFW或firewalld防火墙${NC}"add_to_report "    ${YELLOW}未检测到UFW或firewalld防火墙${NC}"
fi# 6. 服务与系统更新检查
echo -e "\n${BLUE}6. 服务状态与系统更新${NC}"
add_to_report "\n6. 服务状态与系统更新"# 6.1 关键服务状态
critical_services="sshd firewalld crond rsyslog docker nginx mysql redis"echo -e "  关键服务状态检查..."
for service in $critical_services; doif systemctl is-active --quiet $service 2>/dev/null; thenecho -e "${GREEN}    服务正常运行: $service${NC}"add_to_report "    ${GREEN}服务正常运行: $service${NC}"elseif systemctl list-unit-files --type=service 2>/dev/null | grep -q "$service"; thenecho -e "${RED}    服务已安装但未运行: $service${NC}"add_to_report "    ${RED}服务已安装但未运行: $service${NC}"elseecho -e "${YELLOW}    服务未安装: $service${NC}"add_to_report "    ${YELLOW}服务未安装: $service${NC}"fifi
done# 6.2 系统更新检查
echo -e "\n  系统更新检查..."
if command -v apt &> /dev/null; thenupdates=$(apt list --upgradable 2>/dev/null | wc -l)security_updates=$(apt list --upgradable 2>/dev/null | grep -i security | wc -l)echo -e "    可用系统更新: $((updates-1)) 个 (其中安全更新: $security_updates 个)"add_to_report "    可用系统更新: $((updates-1)) 个 (其中安全更新: $security_updates 个)"
elif command -v yum &> /dev/null; thenupdates=$(yum check-update 2>/dev/null | wc -l)security_updates=$(yum check-update --security 2>/dev/null | wc -l)echo -e "    可用系统更新: $((updates-1)) 个 (其中安全更新: $security_updates 个)"add_to_report "    可用系统更新: $((updates-1)) 个 (其中安全更新: $security_updates 个)"
elseecho -e "    系统更新检查: 不支持的包管理器"add_to_report "    系统更新检查: 不支持的包管理器"
fi# 7. 日志与定时任务检查
echo -e "\n${BLUE}7. 日志与定时任务检查${NC}"
add_to_report "\n7. 日志与定时任务检查"# 7.1 错误日志检查
echo -e "  系统错误日志检查..."
if [ -f "/var/log/messages" ]; thenerror_logs=$(grep -iE "error|fail|critical|alert|emergency" /var/log/messages 2>/dev/null | grep -v "CRON" | tail -10)
elif [ -f "/var/log/syslog" ]; thenerror_logs=$(grep -iE "error|fail|critical|alert|emergency" /var/log/syslog 2>/dev/null | grep -v "CRON" | tail -10)
elseerror_logs=""
fiif [ -n "$error_logs" ]; thenecho -e "${YELLOW}    发现错误日志记录:${NC}"echo "$error_logs" | while read line; doecho "      $line"add_to_report "      $line"done
elseecho -e "${GREEN}    未发现明显错误日志${NC}"add_to_report "    ${GREEN}未发现明显错误日志${NC}"
fi# 7.2 登录失败检查
echo -e "\n  登录失败记录检查..."
if [ -f "/var/log/secure" ]; thenfailed_logins=$(grep "Failed password" /var/log/secure 2>/dev/null | tail -5)
elif [ -f "/var/log/auth.log" ]; thenfailed_logins=$(grep "Failed password" /var/log/auth.log 2>/dev/null | tail -5)
elsefailed_logins=""
fiif [ -n "$failed_logins" ]; thenecho -e "${YELLOW}    发现登录失败记录:${NC}"echo "$failed_logins" | while read line; doecho "      $line"add_to_report "      $line"done
elseecho -e "${GREEN}    未发现登录失败记录${NC}"add_to_report "    ${GREEN}未发现登录失败记录${NC}"
fi# 7.3 定时任务检查
echo -e "\n  定时任务安全检查..."
suspicious_crons=$(grep -r -E 'wget|curl|bash -i|nc |netcat' /etc/cron* 2>/dev/null | grep -v -E '#|/usr/bin/' || echo "")
if [ -n "$suspicious_crons" ]; thenecho -e "${YELLOW}    发现可能存在风险的定时任务:${NC}"echo "$suspicious_crons" | while read line; doecho "      $line"add_to_report "      $line"done
elseecho -e "${GREEN}    未发现明显风险的系统级定时任务${NC}"add_to_report "    ${GREEN}未发现明显风险的系统级定时任务${NC}"
fi# 巡检总结
echo -e "\n${YELLOW}===== 系统综合巡检完成 ====="
echo "巡检报告已保存至: $REPORT_FILE"
echo "重点关注项:"summary_warnings=""
if command -v bc &> /dev/null && [ "$sys_max_open" -gt 0 ]; thenusage_rate=$(echo "scale=2; $sys_current_max / $sys_max_open * 100" | bc)if (( $(echo "$usage_rate > 80" | bc -l) )); then echo "  - 系统句柄使用率过高"summary_warnings="$summary_warnings\n  - 系统句柄使用率过高"fi
fiif [ "$cpu_usage" != "未知" ] && command -v bc &> /dev/null; thenif (( $(echo "$cpu_usage > 80" | bc -l) )); then echo "  - CPU使用率过高"summary_warnings="$summary_warnings\n  - CPU使用率过高"fi
fiif [ "$mem_used_percent" != "未知" ] && command -v bc &> /dev/null; thenif (( $(echo "$mem_used_percent > 85" | bc -l) )); then echo "  - 内存使用率过高"summary_warnings="$summary_warnings\n  - 内存使用率过高"fi
fiif [ -n "$empty_passwords" ] || [ -n "$privileged_users" ]; then echo "  - 用户安全配置存在问题"summary_warnings="$summary_warnings\n  - 用户安全配置存在问题"
fiif [ -z "$summary_warnings" ]; thenecho "  - 未发现严重问题"
fiecho "=========================${NC}"add_to_report "\n===== 巡检总结 ====="
add_to_report "检查完成时间: $(date)"
add_to_report "重点关注项:"
if [ -n "$summary_warnings" ]; thenadd_to_report "$summary_warnings"
elseadd_to_report "  - 未发现严重问题"
fiecho -e "\n${GREEN}系统巡检完成!详细报告请查看: $REPORT_FILE${NC}"

执行

chmod +x check.sh
./check.sh
cat system_inspection_20250930_151222.log
http://www.dtcms.com/a/427111.html

相关文章:

  • 广州建站快车加盟网网站建设策划书
  • 12306网站架构站长之家seo综合
  • 学习:uniapp全栈微信小程序vue3后台-额外/精彩报错篇
  • 【云服务器相关】云服务器与P2P
  • vscode终端输出中文乱码一种解决方法
  • 脑机接口(BCI):从信号到交互的工程实践
  • 更改mysql密码
  • 同步与互斥
  • Java Web搭建商城首页
  • STP生成树(h3c)
  • 深圳汇网网站建设移动互联网时代的到来为很多企业提供了新的商业机会
  • 安卓接入Bigo广告源
  • 安卓Handler+Messenger实现跨应用通讯
  • 公司网站建设完成通知重庆市工程建设交易中心网站
  • 北京网站设计公司hlh成都柚米科技15企业营销型网站系统
  • 德州网站建设招聘帝国网站怎么仿站
  • 15. C++ 类的转换
  • 基于STM32与influxDB的电力监控系统-7
  • python 之 argparse的简单使用
  • 开源 java android app 开发(十七)封库--混淆源码
  • windows显示驱动开发-IddCx 对象
  • 图书馆网站建设的作用广州新建站
  • (27)APS.NET Core8.0 堆栈原理通俗理解
  • SVN 一些命令疑问
  • 精读 C++20 设计模式:行为型设计模式 — 状态机模式
  • 多周期路径约束
  • Webpack配置之path.join、path.resolve和__dirname详解
  • vue打包优化方案都有哪些?
  • Golang 中的字符串:常见错误和最佳实践
  • 花生壳建设网站怎样做网络营销推广