#!/bin/sh# defines a function that checks the operating system version num_version=$ (UNAME&NBSP;-R) function check_os () {[[ $NUM _version =~ el6 ]] && return 0| | return 1}echo "##### #CPU使用情况 ######" cpu_hardware=$ (cat /proc/cpuinfo | grep name &NBSP;|CUT&NBSP;-F2&NBSP;-D:&NBSP;|&NBSP;UNIQ&NBSP;-C) cpu_number=$ (cat /proc/cpuinfo | grep name |cut -f2 -d: | uniq -c | awk ' {print $1} ') cpu_ load=$ (uptime | awk ' {for (i=6;i<=nf;i++) printf $i "" fs;print ""} ") Cpu_load_ number=$ (uptime | awk -f "load average:" ' {print $2} ' | awk -f "," ' {print $1} ' | awk -f '. " ' {print $1} ' |sed ' s/^[ \t]*//g ') cpu_utiliz=$ (top -n 1 | grep "Cpu (s)") if [[ $CPU _load_number -lt $CPU _number ]] then cpu_ status= Normal else cpu_status= abnormal fiecho "$CPU _status (" $CPU _hardware, $CPU _load, $CPU _utiliz ")" echo -eecho -eecho "##### #磁盘使用情况 ###### "ifs=" " for i in " df -hp | sed 1d | awk ' {print $ (NF-1) "\ t" $NF "\ T" $ (NF-2)} ' do disk_utiliz=$ (echo $i | awk ' {print $1} ') mount_disk=$ (echo $i |awk ' {print $2} ') disk_free=$ (echo $i |awk ' {print $3} ') if [[ $ (echo $DISK _utiliz | sed s/%//g) -gt 70 ]] then echo "Unhealthy" ("$MOUNT _disk" usage "$DISK _utiliz" larger, please note "") " else continue fidoneecho -eecho "Disk Specific usage:" df -hp | sed 1d | awk ' {print $ NF "Partition" "Remaining Space" $ (NF-2), "utilization" $ (NF-1)} ' umail_dir=$ (cat /usr/local/u-mail/config/custom.conf | grep "MailrooT " | awk -f" = " ' {print $2} ' | sed ' s/^[ \t]*//g ') echo " The message data is stored in the "$UMAIL _direcho -eecho -eecho " ##### #内存使用情况 ###### "check_osresult=$?if [ ${ result} -eq 0 ] then mem_sum_num=$ (free -m | grep "MEM:" | awk -f " " ' {print $2} ') mem_surplus_num=$ (free -m | grep "Mem:" | awk ' {for (i=4;i<=nf;i++) print $i "" FS;} ' | awk ' {a+=$1}end{print a} ') mem_sum=$ (free -m | grep "MEM : " | awk -f" " ' {print $2" M "} ') mem_surplus=$ (free -m | grep "Mem:" | awk ' {for (i=4;i<=nf;i++) print $i "" FS;} ' | awk ' {a+=$1}end{print a ' M "} ') mem_used=$ (echo $ ($MEM _sum_num-$MEM _ Surplus_num)) percent=$ (printf "%d%%" $ (($MEM _uSed*100/$MEM _sum_num)) percent_num=$ (echo $PERCENT |sed s/%//g) if [[ $PERCENT _num -lt 70 ]] then mem_ status= normal else mem_status= not normal fi echo $MEM _status ("Total memory Size" $MEM _sum, "Remaining memory Size" $MEM _surplus, "Memory usage $PERCENT") else mem _sum_num7=$ (free -m | grep "Mem:" | awk -f " " ' {print $2} ') mem_surplus_num7=$ (free -m | grep "MEM:" | awk -f " " ' {print $4} ') mem_sum7=$ (free -m | grep "MEM:" | awk -f " " ' {print $2" M "} ') mem_surplus7=$ (free -m | grep " MEM: " | awk -f " " ' {print $4 "M"} ') mem_used7=$ (echo $ ($MEM _sum_num7-$MEM _ SURPLUS_NUM7)) &NBSP;&NBsp percent7=$ (printf "%d%%" $ (($MEM _used7*100/$MEM _sum_num7)) percent_num7=$ (echo $ percent7|sed s/%//g) if [[ $PERCENT _num7 -lt 70 ]] then mem_status= Normal else mem_status= fi echo $MEM _status ("Total memory Size" $MEM _sum7, "Remaining memory size" $ MEM_SURPLUS7, "Memory usage" $PERCENT 7 ")" fi echo -eecho -eecho "##### #操作系统版本和邮件系统版本 ######" Os_ version=$ (cat /etc/redhat-release) umailapp_version=$ (rpm -qa | grep umail_app | awk -f "." ' {print $1 '. " $ "." $ umailweb_version=$} ') (Rpm -qa | grep umail_webmail | awk -f ". ' {print $1 '. " $ "." $ echo $OS _version, $UMAILAPP _version, $UMAILWEB _versionecho -eecho -eecho "###### System basic operation is normal ###### "ssh_sum=$ (cat /var/log/secure | grep "Authentication failure" | wc -l) ssh_diy=500if [ $SSH _sum -gt $SSH _diy ] then echo "Someone is trying your root password, please note" else echo "normal" Fiecho -eecho -eecho "##### #是否有可疑进程或后门 ######" echo "normal" echo -eecho -eecho "###### Whether to install anti-virus software firewall ###### "check_osresult=$?if [ ${result} -eq 0 ] then /etc/ Init.d/iptables status 1>/dev/null 2>&1 result_iptables=$? if [ ${RESULT_IPTABLES} -eq 0 ] then echo "Operating system comes with firewall turned on" else echo "OS comes with firewall not turned on" fi else systemctl status firewalld.service 1>/dev/null 2>&1 Result_firewalld=$? if [ ${result_firewalld} -eq 0 ] then echo "Operating system comes with firewall turned on" else echo "OS comes with firewall not turned on" fi ficheck_osresult=$?if [ ${result} -eq 0 ] then ps - Ef | grep umail_clamd | grep -v grep 1>/dev/null 2>&1 RESULT_CLAMD6=$? /etc/init.d/umail_clamd status 1>/dev/null 2> &1 result_clamdstatus6=$? if [ ${result_clamd6} -eq 0 ] && [ ${result_clamdstatus6} -eq 0 ] then echo "Installed CLAMD anti-virus software" else echo "No antivirus software installed or failed to start" fi else ps -ef | grep umail_clamd | grep -v grep 1>/dev/null 2>&1 RESULT_CLAMD7=$? systemctl status Umail_clamd.service 1>/dev/null 2>&1 result_clamdstatus7=$? if [ ${result_clamd7} -eq 0 ] && [ ${result_clamdstatus7} - eq 0 ] then echo "Installed CLAMD anti-virus software" else echo "No antivirus software installed or failed to start" fifiecho -eecho -eecho "##### #开机时长 ######" linetime=$ (uptime | awk -f "Up" ' {print $2} ' | awk -f ", load average" ' {print $1} ') echo "Server boot Time is" $LINETIMEecho -eecho -eecho "##### #HTTP服务 ######" apache6_status=$ (/etc/init.d/umail_apache status 1 >/dev/null 2>&1) nginx6_status=$ (/etc/init.d/umail_nginx status 1>/dev/null 2>&1) apache7_status=$ (systemctl status umail_apache.service 1>/dev/null 2 >&1) NGINX7_status=$ (systemctl status umail_nginx.service 1>/dev/null 2>&1) APACHE_PROC=$ ( ps -ef | grep "/USR/LOCAL/U-MAIL/SERVICE/APACHE/BIN/HTTPD" | grep -v grep 1>/dev/null 2>&1) nginx_proc=$ (ps -ef | grep "/usr/local/u-mail/ Service/nginx/sbin/nginx " | grep -v grep 1>/dev/null 2>&1) Check_ osresult=$?if [ ${result} -eq 0 ] then /etc/init.d/umail_apache Status 1>/dev/null 2>&1 result_apache6=$? /etc/init.d/umail_nginx status 1>/dev/null 2>&1 result_nginx6=$? ps -ef | grep "/USR/LOCAL/U-MAIL/SERVICE/APACHE/BIN/HTTPD" | grep -v grep 1>/dev /null 2>&1 result_apacheproc6=$? ps -ef | grep "/usr/ Local/u-mail/service/nginx/sbIn/nginx " | grep -v grep 1>/dev/null 2>&1 result_nginxproc6 =$? if [ ${result_apache6} -eq 0 ] && [ ${result_ nginx6} -eq 0 ] && [ ${result_apacheproc6} -eq 0 ] && [ ${RESULT_NGINXPROC6} -eq 0 ] then echo "HTTP service started successfully" else echo "HTTP service startup unsuccessful" Fi else systemctl status umail_apache.service 1>/dev/null 2>&1 result_apache7=$? systemctl status umail_nginx.service 1>/dev/null 2>&1 RESULT_NGINX7=$? ps -ef | grep "/usr/local/u-mail/ SERVICE/APACHE/BIN/HTTPD " | grep -v grep 1>/dev/null 2>&1 Result_apacheproc7=$? ps -ef | grep "/usr/local/u-mail/service/nginx/sbin/nginx" | grep -v grep 1>/dev/null 2>&1 result_nginxproc7=$? if [ ${ RESULT_APACHE7}&NBSP;-EQ&NBSP;0&NBSP;]&NBSP;&&&NBSP;[&NBSP;${RESULT_NGINX7}&NBSP;-EQ&NBSP;0&NBSP;] && [ ${result_apacheproc7} -eq 0 ] && [ ${result _nginxproc7} -eq 0 ] then echo "HTTP service started successfully" else echo "HTTP service failed to start successfully" fifiecho -eecho - eecho "##### #SMTP服务 ######" Check_osresult=$?if [ ${result} -eq 0 ] then netstat -anltp | grep ":" 1>/dev/null 2>&1 result_smtp=$? /etc/init.d/umail_postfix status 1>/dev/null 2>&1 result_postfix=$? if [ ${result_smtp} -eq 0 ] && [ ${result_postfix} -eq 0 ] then echo "SMTP Service started successfully" else echo "SMTP Service failed to start successfully" &NBSP;&NBSP;FI&NBSP;ELSE&NBSP;&NBSP;NETSTAT&NBSP;-ANLTP | grep ":" 1>/dev/null 2>&1 RESULT_SMTP7=$? Systemctl status umail_postfix.service 1>/dev/null 2>&1 result_ postfix7=$? if [ ${result_smtp7} -eq 0 ] && [ ${ result_postfix7} -eq 0 ] then echo "SMTP Service started successfully" else echo "SMTP Service failed to start successfully" fifiecho -eecho - eecho "##### #POP服务 ######" check_osresult=$?if [ ${result} -eq 0 ] then netstat -anltp | grep ":" 1>/dev/null 2>&1 result_pop=$? /etc/init.d/umail_ dovecot status 1>/dev/null 2>&1 result_popproc=$? if [ ${RESULT_POP} -eq 0 ] && [ ${RESULT_POPPROC} -eq 0 ] then echo "Pop service started successfully" else echo "Pop service failed to start" fi else netstat -anltp | grep " : " 1>/dev/null 2>&1 RESULT_POP7=$? systemctl status umail_dovecot.service 1>/dev/null 2>&1 result_popproc7=$? if [ ${result_pop7} -eq 0 ] && [ ${result_popproc7} -eq 0 ] then echo "Pop service started successfully" else echo "Pop service failed to start" fifiecho -eecho -eecho " ##### #IMAP服务 ###### "check_osresult=$?if [ ${ result} -eq 0 ] then netstat -anltp | grep ": 143" 1 >/dev/null 2>&1 result_imap=$? /etc/init.d/umail_dovecot status 1>/dev/null 2>&1 result_imapproc=$? if [ ${result_imap} -eq 0 ] && [ ${RESULT_IMAPPROC} -eq 0 ] then echo "IMAP service started successfully" else echo "IMAP service failed to start" fi else netstat -anltp | grep ": 143" 1 >/dev/null 2>&1 result_imap7=$? systemctl status umail_ dovecot.service 1>/dev/null 2>&1 result_imapproc7=$? if [ ${result_imap7} -eq 0 ] && [ ${result_imapproc7} -eq 0 ] then echo "IMAP service started successfully" else echo "IMAP service started unsuccessfully" fifiecho -eecho -eecho "##### #收发测试 (web and client) ######" echo "normal" Echo -eecho -eecho "##### #管理后台功能测试 ######" echo "normal" echo -eecho -eecho "##### #反垃圾反病毒测试 ######" echo " Normal "echo -eecho -eecho " ##### #是否有密码泄露导致群发垃圾邮件现象 ###### "smtp_sum=$ (cat /usr/local/u-mail/app/ log/smtp.log | grep "From:" | awk -F " " ' { print $6 &NBSP,} ' | sed ' s/<//g ' | sed ' s/>,//g ' | sort | uniq -c | sort -rn |sed ' s/^[ \t]*//g ' |head -n 1 | Awk -f " " ' {print $1} ') smtp_user=$ (cat /usr/local/u-mail/app/log/smtp.log | grep "From:" | awk -f " " ' { print $6 } ' | sed ' s/<//g ' | sed ' s/>,//g ' | sort | uniq -c | sort -rn |sed ' s/^[ \t]*//g ' |head -n 1 | awk -f " " ' {print $2} ') smtp_diy=500if [ $SMTP _sum -gt $SMTP _diy ] then echo " The "$SMTP _user" user with the largest number of outgoing messages on the day exceeds the "$SMTP _diy" seal, please confirm " else echo normal" fiecho -eecho -e
The results of the operation are as follows:
[[email protected] ~]# sh check_umail.sh ##### #CPU使用情况 ##### #正常 ( 2 intel (R) xeon (R) CPU E5606 @ 2.13GHz,1 user, load average: 0.06, 0.02,&NBSP;0.00&NBSP;,CPU (s): 2.1%us, 0.8%sy, 0.2%ni, 96.5%id, 0.3%wa, 0.0%hi, 0.2%si, 0.0%st) ##### #磁盘使用情况 ##### #磁盘具体使用情况:/partition remaining space 38g utilization 20%/DEV/SHM partition remaining space 1.9g usage 1%/ Boot partition remaining space 425m usage 7%/home partition remaining space 434g usage 38% message data is stored in/home/mailbox##### #内存使用情况 ##### #正常 (total memory Size 3952M, Remaining memory size 3028M, Memory utilization 23%) ##### #操作系统版本和邮件系统版本 ##### #CentOS release 6.9 (Final), Umail_app-2.2.44-2, umail_webmail-1.6.69-1##### #系统基本操作是否正常 ##### #正常 ##### #是否有可疑进程或后门 ##### #正常 ##### #是否安装杀毒软件防火墙 ###### The operating system comes with a firewall already installed CLAMD antivirus ##### #开机时长 ##### #服务器开机时间为 33 days, 6:29, 1 user##### #HTTP服务 # # # # # #HTTP服务启动成功 ##### #SMTP服务 ##### #SMTP服务启动成功 ##### #POP服务 ##### #POP服务启动成功 ##### #IMAP服务 ##### #IMAP服务启动成功 ##### #收发测试 ( Web and client) ##### #正常 ##### #管理后台功能测试 ##### #正常 ##### #反垃圾反病毒测Try ##### #正常 ##### #是否有密码泄露导致群发垃圾邮件现象 ##### #正常
Server auto-patrol shell script