{"id":668,"date":"2022-06-05T17:41:34","date_gmt":"2022-06-05T09:41:34","guid":{"rendered":"https:\/\/www.bunnyism.com\/?p=668"},"modified":"2024-12-19T17:45:45","modified_gmt":"2024-12-19T09:45:45","slug":"%e6%97%a5%e5%b8%b8%e5%b7%a1%e6%a3%80%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/www.bunnyism.com\/?p=668","title":{"rendered":"Linux\u65e5\u5e38\u5de1\u68c0\u811a\u672c"},"content":{"rendered":"<blockquote><p>#!\/bin\/bash<br \/>\n#1\u3001\u4e3b\u673a\u4fe1\u606f\u6bcf\u65e5\u5de1\u68c0<\/p>\n<p>IPADDR=$(ifconfig eth0|grep &#8216;inet addr&#8217;|awk -F &#8216;[ :]&#8217; &#8216;{print $13}&#8217;)<br \/>\n# 2\u3001\u73af\u5883\u53d8\u91cfPATH\u6ca1\u8bbe\u597d\uff0c\u5728cron\u91cc\u6267\u884c\u65f6\u6709\u5f88\u591a\u547d\u4ee4\u4f1a\u627e\u4e0d\u5230<br \/>\nexport PATH=\/usr\/local\/sbin:\/usr\/local\/bin:\/sbin:\/bin:\/usr\/sbin:\/usr\/bin:\/root\/bin<br \/>\nsource \/etc\/profile<\/p>\n<p>[ $(id -u) -gt 0 ] &amp;&amp; echo &#8220;\u8bf7\u7528root\u7528\u6237\u6267\u884c\u6b64\u811a\u672c\uff01&#8221; &amp;&amp; exit 1<br \/>\ncentosVersion=$(awk &#8216;{print $(NF-1)}&#8217; \/etc\/redhat-release)<br \/>\nVERSION=&#8221;2022-1-12&#8243;<\/p>\n<p># 3\u3001\u65e5\u5fd7\u76f8\u5173<br \/>\nPROGPATH=`echo $0 | sed -e &#8216;s,[\\\\\/][^\\\\\/][^\\\\\/]*$,,&#8217;`<br \/>\n[ -f $PROGPATH ] &amp;&amp; PROGPATH=&#8221;.&#8221;<br \/>\nLOGPATH=&#8221;$PROGPATH\/log&#8221;<br \/>\n[ -e $LOGPATH ] || mkdir $LOGPATH<br \/>\nRESULTFILE=&#8221;$LOGPATH\/HostDailyCheck-$IPADDR-`date +%Y%m%d`.txt&#8221;<\/p>\n<p># 4\u3001\u5b9a\u4e49\u62a5\u8868\u7684\u5168\u5c40\u53d8\u91cf<br \/>\nreport_DateTime=&#8221;&#8221; #\u65e5\u671f ok<br \/>\nreport_Hostname=&#8221;&#8221; #\u4e3b\u673a\u540d ok<br \/>\nreport_OSRelease=&#8221;&#8221; #\u53d1\u884c\u7248\u672c ok<br \/>\nreport_Kernel=&#8221;&#8221; #\u5185\u6838 ok<br \/>\nreport_Language=&#8221;&#8221; #\u8bed\u8a00\/\u7f16\u7801 ok<br \/>\nreport_LastReboot=&#8221;&#8221; #\u6700\u8fd1\u542f\u52a8\u65f6\u95f4 ok<br \/>\nreport_Uptime=&#8221;&#8221; #\u8fd0\u884c\u65f6\u95f4\uff08\u5929\uff09 ok<br \/>\nreport_CPUs=&#8221;&#8221; #CPU\u6570\u91cf ok<br \/>\nreport_CPUType=&#8221;&#8221; #CPU\u7c7b\u578b ok<br \/>\nreport_Arch=&#8221;&#8221; #CPU\u67b6\u6784 ok<br \/>\nreport_MemTotal=&#8221;&#8221; #\u5185\u5b58\u603b\u5bb9\u91cf(MB) ok<br \/>\nreport_MemFree=&#8221;&#8221; #\u5185\u5b58\u5269\u4f59(MB) ok<br \/>\nreport_MemUsedPercent=&#8221;&#8221; #\u5185\u5b58\u4f7f\u7528\u7387% ok<br \/>\nreport_DiskTotal=&#8221;&#8221; #\u786c\u76d8\u603b\u5bb9\u91cf(GB) ok<br \/>\nreport_DiskFree=&#8221;&#8221; #\u786c\u76d8\u5269\u4f59(GB) ok<br \/>\nreport_DiskUsedPercent=&#8221;&#8221; #\u786c\u76d8\u4f7f\u7528\u7387% ok<br \/>\nreport_InodeTotal=&#8221;&#8221; #Inode\u603b\u91cf ok<br \/>\nreport_InodeFree=&#8221;&#8221; #Inode\u5269\u4f59 ok<br \/>\nreport_InodeUsedPercent=&#8221;&#8221; #Inode\u4f7f\u7528\u7387 ok<br \/>\nreport_IP=&#8221;&#8221; #IP\u5730\u5740 ok<br \/>\nreport_MAC=&#8221;&#8221; #MAC\u5730\u5740 ok<br \/>\nreport_Gateway=&#8221;&#8221; #\u9ed8\u8ba4\u7f51\u5173 ok<br \/>\nreport_DNS=&#8221;&#8221; #DNS ok<br \/>\nreport_Listen=&#8221;&#8221; #\u76d1\u542c ok<br \/>\nreport_Selinux=&#8221;&#8221; #Selinux ok<br \/>\nreport_Firewall=&#8221;&#8221; #\u9632\u706b\u5899 ok<br \/>\nreport_USERs=&#8221;&#8221; #\u7528\u6237 ok<br \/>\nreport_USEREmptyPassword=&#8221;&#8221; #\u7a7a\u5bc6\u7801\u7528\u6237 ok<br \/>\nreport_USERTheSameUID=&#8221;&#8221; #\u76f8\u540cID\u7684\u7528\u6237 ok<br \/>\nreport_PasswordExpiry=&#8221;&#8221; #\u5bc6\u7801\u8fc7\u671f\uff08\u5929\uff09 ok<br \/>\nreport_RootUser=&#8221;&#8221; #root\u7528\u6237 ok<br \/>\nreport_Sudoers=&#8221;&#8221; #sudo\u6388\u6743 ok<br \/>\nreport_SSHAuthorized=&#8221;&#8221; #SSH\u4fe1\u4efb\u4e3b\u673a ok<br \/>\nreport_SSHDProtocolVersion=&#8221;&#8221; #SSH\u534f\u8bae\u7248\u672c ok<br \/>\nreport_SSHDPermitRootLogin=&#8221;&#8221; #\u5141\u8bb8root\u8fdc\u7a0b\u767b\u5f55 ok<br \/>\nreport_DefunctProsess=&#8221;&#8221; #\u50f5\u5c38\u8fdb\u7a0b\u6570\u91cf ok<br \/>\nreport_SelfInitiatedService=&#8221;&#8221; #\u81ea\u542f\u52a8\u670d\u52a1\u6570\u91cf ok<br \/>\nreport_SelfInitiatedProgram=&#8221;&#8221; #\u81ea\u542f\u52a8\u7a0b\u5e8f\u6570\u91cf ok<br \/>\nreport_RuningService=&#8221;&#8221; #\u8fd0\u884c\u4e2d\u670d\u52a1\u6570 ok<br \/>\nreport_Crontab=&#8221;&#8221; #\u8ba1\u5212\u4efb\u52a1\u6570 ok<br \/>\nreport_Syslog=&#8221;&#8221; #\u65e5\u5fd7\u670d\u52a1 ok<br \/>\nreport_SNMP=&#8221;&#8221; #SNMP OK<br \/>\nreport_NTP=&#8221;&#8221; #NTP ok<br \/>\nreport_JDK=&#8221;&#8221; #JDK\u7248\u672c ok<br \/>\nfunction version(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u7cfb\u7edf\u5de1\u68c0\u811a\u672c\uff1aVersion $VERSION&#8221;<br \/>\n}<\/p>\n<p>function getCpuStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ CPU\u68c0\u67e5 #############################&#8221;<br \/>\nPhysical_CPUs=$(grep &#8220;physical id&#8221; \/proc\/cpuinfo| sort | uniq | wc -l)<br \/>\nVirt_CPUs=$(grep &#8220;processor&#8221; \/proc\/cpuinfo | wc -l)<br \/>\nCPU_Kernels=$(grep &#8220;cores&#8221; \/proc\/cpuinfo |sort -r |uniq |awk -F &#8216;: &#8216; &#8216;{print $2}&#8217;)<br \/>\nCPU_Type=$(grep &#8220;model name&#8221; \/proc\/cpuinfo | awk -F &#8216;: &#8216; &#8216;{print $2}&#8217; | sort | uniq)<br \/>\nCPU_Arch=$(uname -m)<br \/>\necho &#8220;\u7269\u7406CPU\u4e2a\u6570:$Physical_CPUs&#8221;<br \/>\necho &#8220;\u903b\u8f91CPU\u4e2a\u6570:$Virt_CPUs&#8221;<br \/>\necho &#8220;\u6bcfCPU\u6838\u5fc3\u6570:$CPU_Kernels&#8221;<br \/>\necho &#8221; CPU\u578b\u53f7:$CPU_Type&#8221;<br \/>\necho &#8221; CPU\u67b6\u6784:$CPU_Arch&#8221;<br \/>\n# 5\u3001CPU\u62a5\u8868\u4fe1\u606f<br \/>\nreport_CPUs=$Virt_CPUs #CPU\u6570\u91cf<br \/>\nreport_CPUType=$CPU_Type #CPU\u7c7b\u578b<br \/>\nreport_Arch=$CPU_Arch #CPU\u67b6\u6784<br \/>\n}<\/p>\n<p>function getMemStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u5185\u5b58\u68c0\u67e5 ############################&#8221;<br \/>\nif [[ $centosVersion &lt; 7 ]];then<br \/>\nfree -mo<br \/>\nelse<br \/>\nfree -h<br \/>\nfi<br \/>\n# 6\u3001\u5185\u5b58\u62a5\u8868\u4fe1\u606f<br \/>\nMemTotal=$(grep MemTotal \/proc\/meminfo| awk &#8216;{print $2}&#8217;) #KB<br \/>\nMemFree=$(grep MemFree \/proc\/meminfo| awk &#8216;{print $2}&#8217;) #KB<br \/>\nlet MemUsed=MemTotal-MemFree<br \/>\nMemPercent=$(awk &#8220;BEGIN {if($MemTotal==0){printf 100}else{printf \\&#8221;%.2f\\&#8221;,$MemUsed*100\/$MemTotal}}&#8221;)<br \/>\nreport_MemTotal=&#8221;$((MemTotal\/1024))&#8221;&#8221;MB&#8221; #\u5185\u5b58\u603b\u5bb9\u91cf(MB)<br \/>\nreport_MemFree=&#8221;$((MemFree\/1024))&#8221;&#8221;MB&#8221; #\u5185\u5b58\u5269\u4f59(MB)<br \/>\nreport_MemUsedPercent=&#8221;$(awk &#8220;BEGIN {if($MemTotal==0){printf 100}else{printf \\&#8221;%.2f\\&#8221;,$MemUsed*100\/$MemTotal}}&#8221;)&#8221;&#8221;%&#8221; #\u5185\u5b58\u4f7f\u7528\u7387%<br \/>\n}<br \/>\nfunction getDiskStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u78c1\u76d8\u68c0\u67e5 ############################&#8221;<br \/>\ndf -hiP | sed &#8216;s\/Mounted on\/Mounted\/&#8217;&gt; \/tmp\/inode<br \/>\ndf -hTP | sed &#8216;s\/Mounted on\/Mounted\/&#8217;&gt; \/tmp\/disk<br \/>\njoin \/tmp\/disk \/tmp\/inode | awk &#8216;{print $1,$2,&#8221;|&#8221;,$3,$4,$5,$6,&#8221;|&#8221;,$8,$9,$10,$11,&#8221;|&#8221;,$12}&#8217;| column -t<br \/>\n# 7\u3001\u78c1\u76d8\u62a5\u8868\u4fe1\u606f<br \/>\ndiskdata=$(df -TP | sed &#8216;1d&#8217; | awk &#8216;$2!=&#8221;tmpfs&#8221;{print}&#8217;) #KB<br \/>\ndisktotal=$(echo &#8220;$diskdata&#8221; | awk &#8216;{total+=$3}END{print total}&#8217;) #KB<br \/>\ndiskused=$(echo &#8220;$diskdata&#8221; | awk &#8216;{total+=$4}END{print total}&#8217;) #KB<br \/>\ndiskfree=$((disktotal-diskused)) #KB<br \/>\ndiskusedpercent=$(echo $disktotal $diskused | awk &#8216;{if($1==0){printf 100}else{printf &#8220;%.2f&#8221;,$2*100\/$1}}&#8217;)<br \/>\ninodedata=$(df -iTP | sed &#8216;1d&#8217; | awk &#8216;$2!=&#8221;tmpfs&#8221;{print}&#8217;)<br \/>\ninodetotal=$(echo &#8220;$inodedata&#8221; | awk &#8216;{total+=$3}END{print total}&#8217;)<br \/>\ninodeused=$(echo &#8220;$inodedata&#8221; | awk &#8216;{total+=$4}END{print total}&#8217;)<br \/>\ninodefree=$((inodetotal-inodeused))<br \/>\ninodeusedpercent=$(echo $inodetotal $inodeused | awk &#8216;{if($1==0){printf 100}else{printf &#8220;%.2f&#8221;,$2*100\/$1}}&#8217;)<br \/>\nreport_DiskTotal=$((disktotal\/1024\/1024))&#8221;GB&#8221; #\u786c\u76d8\u603b\u5bb9\u91cf(GB)<br \/>\nreport_DiskFree=$((diskfree\/1024\/1024))&#8221;GB&#8221; #\u786c\u76d8\u5269\u4f59(GB)<br \/>\nreport_DiskUsedPercent=&#8221;$diskusedpercent&#8221;&#8221;%&#8221; #\u786c\u76d8\u4f7f\u7528\u7387%<br \/>\nreport_InodeTotal=$((inodetotal\/1000))&#8221;K&#8221; #Inode\u603b\u91cf<br \/>\nreport_InodeFree=$((inodefree\/1000))&#8221;K&#8221; #Inode\u5269\u4f59<br \/>\nreport_InodeUsedPercent=&#8221;$inodeusedpercent&#8221;&#8221;%&#8221; #Inode\u4f7f\u7528\u7387%<\/p>\n<p>}<\/p>\n<p>function getSystemStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u7cfb\u7edf\u68c0\u67e5 ############################&#8221;<br \/>\nif [ -e \/etc\/sysconfig\/i18n ];then<br \/>\ndefault_LANG=&#8221;$(grep &#8220;LANG=&#8221; \/etc\/sysconfig\/i18n | grep -v &#8220;^#&#8221; | awk -F &#8216;&#8221;&#8216; &#8216;{print $2}&#8217;)&#8221;<br \/>\nelse<br \/>\ndefault_LANG=$LANG<br \/>\nfi<br \/>\nexport LANG=&#8221;en_US.UTF-8&#8243;<br \/>\nRelease=$(cat \/etc\/redhat-release 2&gt;\/dev\/null)<br \/>\nKernel=$(uname -r)<br \/>\nOS=$(uname -o)<br \/>\nHostname=$(uname -n)<br \/>\nSELinux=$(\/usr\/sbin\/sestatus | grep &#8220;SELinux status: &#8221; | awk &#8216;{print $3}&#8217;)<br \/>\nLastReboot=$(who -b | awk &#8216;{print $3,$4}&#8217;)<br \/>\nuptime=$(uptime | sed &#8216;s\/.*up \\([^,]*\\), .*\/\\1\/&#8217;)<br \/>\necho &#8221; \u7cfb\u7edf\uff1a$OS&#8221;<br \/>\necho &#8221; \u53d1\u884c\u7248\u672c\uff1a$Release&#8221;<br \/>\necho &#8221; \u5185\u6838\uff1a$Kernel&#8221;<br \/>\necho &#8221; \u4e3b\u673a\u540d\uff1a$Hostname&#8221;<br \/>\necho &#8221; SELinux\uff1a$SELinux&#8221;<br \/>\necho &#8220;\u8bed\u8a00\/\u7f16\u7801\uff1a$default_LANG&#8221;<br \/>\necho &#8221; \u5f53\u524d\u65f6\u95f4\uff1a$(date +&#8217;%F %T&#8217;)&#8221;<br \/>\necho &#8221; \u6700\u540e\u542f\u52a8\uff1a$LastReboot&#8221;<br \/>\necho &#8221; \u8fd0\u884c\u65f6\u95f4\uff1a$uptime&#8221;<br \/>\n# 8\u3001\u5185\u6838\u62a5\u8868\u4fe1\u606f<br \/>\nreport_DateTime=$(date +&#8221;%F %T&#8221;) #\u65e5\u671f<br \/>\nreport_Hostname=&#8221;$Hostname&#8221; #\u4e3b\u673a\u540d<br \/>\nreport_OSRelease=&#8221;$Release&#8221; #\u53d1\u884c\u7248\u672c<br \/>\nreport_Kernel=&#8221;$Kernel&#8221; #\u5185\u6838<br \/>\nreport_Language=&#8221;$default_LANG&#8221; #\u8bed\u8a00\/\u7f16\u7801<br \/>\nreport_LastReboot=&#8221;$LastReboot&#8221; #\u6700\u8fd1\u542f\u52a8\u65f6\u95f4<br \/>\nreport_Uptime=&#8221;$uptime&#8221; #\u8fd0\u884c\u65f6\u95f4\uff08\u5929\uff09<br \/>\nreport_Selinux=&#8221;$SELinux&#8221;<br \/>\nexport LANG=&#8221;$default_LANG&#8221;<\/p>\n<p>}<\/p>\n<p>function getServiceStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u670d\u52a1\u68c0\u67e5 ############################&#8221;<br \/>\necho &#8220;&#8221;<br \/>\nif [[ $centosVersion &gt; 7 ]];then<br \/>\nconf=$(systemctl list-unit-files &#8211;type=service &#8211;state=enabled &#8211;no-pager | grep &#8220;enabled&#8221;)<br \/>\nprocess=$(systemctl list-units &#8211;type=service &#8211;state=running &#8211;no-pager | grep &#8220;.service&#8221;)<br \/>\n# 9\u3001\u670d\u52a1\u62a5\u8868\u4fe1\u606f<br \/>\nreport_SelfInitiatedService=&#8221;$(echo &#8220;$conf&#8221; | wc -l)&#8221; #\u81ea\u542f\u52a8\u670d\u52a1\u6570\u91cf<br \/>\nreport_RuningService=&#8221;$(echo &#8220;$process&#8221; | wc -l)&#8221; #\u8fd0\u884c\u4e2d\u670d\u52a1\u6570\u91cf<br \/>\nelse<br \/>\nconf=$(\/sbin\/chkconfig | grep -E &#8220;:on|:\u542f\u7528&#8221;)<br \/>\nprocess=$(\/sbin\/service &#8211;status-all 2&gt;\/dev\/null | grep -E &#8220;is running|\u6b63\u5728\u8fd0\u884c&#8221;)<br \/>\n# 10\u3001\u670d\u52a1\u62a5\u8868\u4fe1\u606f<br \/>\nreport_SelfInitiatedService=&#8221;$(echo &#8220;$conf&#8221; | wc -l)&#8221; #\u81ea\u542f\u52a8\u670d\u52a1\u6570\u91cf<br \/>\nreport_RuningService=&#8221;$(echo &#8220;$process&#8221; | wc -l)&#8221; #\u8fd0\u884c\u4e2d\u670d\u52a1\u6570\u91cf<br \/>\nfi<br \/>\necho &#8220;\u670d\u52a1\u914d\u7f6e&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8211;&#8221;<br \/>\necho &#8220;$conf&#8221; | column -t<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u6b63\u5728\u8fd0\u884c\u7684\u670d\u52a1&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8211;&#8221;<br \/>\necho &#8220;$process&#8221;<\/p>\n<p>}<\/p>\n<p>function getAutoStartStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u81ea\u542f\u52a8\u68c0\u67e5 ##########################&#8221;<br \/>\nconf=$(grep -v &#8220;^#&#8221; \/etc\/rc.d\/rc.local| sed &#8216;\/^$\/d&#8217;)<br \/>\necho &#8220;$conf&#8221;<br \/>\n# 12\u3001\u670d\u52a1\u62a5\u8868\u4fe1\u606f<br \/>\nreport_SelfInitiatedProgram=&#8221;$(echo $conf | wc -l)&#8221; #\u81ea\u542f\u52a8\u7a0b\u5e8f\u6570\u91cf<br \/>\n}<\/p>\n<p>function getLoginStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u767b\u5f55\u68c0\u67e5 ############################&#8221;<br \/>\nlast | head<br \/>\n}<\/p>\n<p>function getNetworkStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u7f51\u7edc\u68c0\u67e5 ############################&#8221;<br \/>\nif [[ $centosVersion &lt; 7 ]];then<br \/>\n\/sbin\/ifconfig -a | grep -v packets | grep -v collisions | grep -v inet6<br \/>\nelse<br \/>\n# 16\u3001IP\u62a5\u8868\u4fe1\u606f<br \/>\nfor i in $(ip link | grep BROADCAST | awk -F: &#8216;{print $2}&#8217;);do ip add show $i | grep -E &#8220;BROADCAST|global&#8221;| awk &#8216;{print $2}&#8217; | tr &#8216;\\n&#8217; &#8216; &#8216; ;echo &#8220;&#8221; ;done<br \/>\nfi<br \/>\nGATEWAY=$(ip route | grep default | awk &#8216;{print $3}&#8217;)<br \/>\nDNS=$(grep nameserver \/etc\/resolv.conf| grep -v &#8220;#&#8221; | awk &#8216;{print $2}&#8217; | tr &#8216;\\n&#8217; &#8216;,&#8217; | sed &#8216;s\/,$\/\/&#8217;)<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u7f51\u5173\uff1a$GATEWAY &#8221;<br \/>\necho &#8221; DNS\uff1a$DNS&#8221;<br \/>\n# 17\u3001IP\u62a5\u8868\u4fe1\u606f<br \/>\nIP=$(ip -f inet addr | grep -v 127.0.0.1 | grep inet | awk &#8216;{print $NF,$2}&#8217; | tr &#8216;\\n&#8217; &#8216;,&#8217; | sed &#8216;s\/,$\/\/&#8217;)<br \/>\nMAC=$(ip link | grep -v &#8220;LOOPBACK\\|loopback&#8221; | awk &#8216;{print $2}&#8217; | sed &#8216;N;s\/\\n\/\/&#8217; | tr &#8216;\\n&#8217; &#8216;,&#8217; | sed &#8216;s\/,$\/\/&#8217;)<br \/>\nreport_IP=&#8221;$IP&#8221; #IP\u5730\u5740<br \/>\nreport_MAC=$MAC #MAC\u5730\u5740<br \/>\nreport_Gateway=&#8221;$GATEWAY&#8221; #\u9ed8\u8ba4\u7f51\u5173<br \/>\nreport_DNS=&#8221;$DNS&#8221; #DNS<br \/>\n}<\/p>\n<p>function getListenStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u76d1\u542c\u68c0\u67e5 ############################&#8221;<br \/>\nTCPListen=$(ss -ntul | column -t)<br \/>\necho &#8220;$TCPListen&#8221;<br \/>\n# 18\u3001\u8ba1\u5212\u4efb\u52a1\u62a5\u8868\u4fe1\u606f<br \/>\nreport_Listen=&#8221;$(echo &#8220;$TCPListen&#8221;| sed &#8216;1d&#8217; | awk &#8216;\/tcp\/ {print $5}&#8217; | awk -F: &#8216;{print $NF}&#8217; | sort | uniq | wc -l)&#8221;<br \/>\n}<\/p>\n<p>function getCronStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u8ba1\u5212\u4efb\u52a1\u68c0\u67e5 ########################&#8221;<br \/>\nCrontab=0<br \/>\nfor shell in $(grep -v &#8220;\/sbin\/nologin&#8221; \/etc\/shells);do<br \/>\nfor user in $(grep &#8220;$shell&#8221; \/etc\/passwd| awk -F: &#8216;{print $1}&#8217;);do<br \/>\ncrontab -l -u $user &gt;\/dev\/null 2&gt;&amp;1<br \/>\nstatus=$?<br \/>\nif [ $status -eq 0 ];then<br \/>\necho &#8220;$user&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8211;&#8221;<br \/>\ncrontab -l -u $user<br \/>\nlet Crontab=Crontab+$(crontab -l -u $user | wc -l)<br \/>\necho &#8220;&#8221;<br \/>\nfi<br \/>\ndone<br \/>\ndone<br \/>\n# 19\u3001\u8ba1\u5212\u4efb\u52a1\u62a5\u8868\u4fe1\u606f<br \/>\nfind \/etc\/cron* -type f | xargs -i ls -l {} | column -t<br \/>\nlet Crontab=Crontab+$(find \/etc\/cron* -type f | wc -l)<br \/>\n# 20\u3001\u8ba1\u5212\u4efb\u52a1\u62a5\u8868\u4fe1\u606f<br \/>\nreport_Crontab=&#8221;$Crontab&#8221; #\u8ba1\u5212\u4efb\u52a1\u6570<br \/>\n}<br \/>\nfunction getHowLongAgo(){<br \/>\n# 21\u3001\u8ba1\u7b97\u4e00\u4e2a\u65f6\u95f4\u6233\u79bb\u73b0\u5728\u6709\u591a\u4e45\u4e86<br \/>\ndatetime=&#8221;$*&#8221;<br \/>\n[ -z &#8220;$datetime&#8221; ] &amp;&amp; echo &#8220;\u9519\u8bef\u7684\u53c2\u6570\uff1agetHowLongAgo() $*&#8221;<br \/>\nTimestamp=$(date +%s -d &#8220;$datetime&#8221;) #\u8f6c\u5316\u4e3a\u65f6\u95f4\u6233<br \/>\nNow_Timestamp=$(date +%s)<br \/>\nDifference_Timestamp=$(($Now_Timestamp-$Timestamp))<br \/>\ndays=0;hours=0;minutes=0;<br \/>\nsec_in_day=$((60*60*24));<br \/>\nsec_in_hour=$((60*60));<br \/>\nsec_in_minute=60<br \/>\nwhile (( $(($Difference_Timestamp-$sec_in_day)) &gt; 1 ))<br \/>\ndo<br \/>\nlet Difference_Timestamp=Difference_Timestamp-sec_in_day<br \/>\nlet days++<br \/>\ndone<br \/>\nwhile (( $(($Difference_Timestamp-$sec_in_hour)) &gt; 1 ))<br \/>\ndo<br \/>\nlet Difference_Timestamp=Difference_Timestamp-sec_in_hour<br \/>\nlet hours++<br \/>\ndone<br \/>\necho &#8220;$days \u5929 $hours \u5c0f\u65f6\u524d&#8221;<br \/>\n}<\/p>\n<p>function getUserLastLogin(){<br \/>\n# 22\u3001\u83b7\u53d6\u7528\u6237\u6700\u8fd1\u4e00\u6b21\u767b\u5f55\u7684\u65f6\u95f4\uff0c\u542b\u5e74\u4efd<br \/>\n# \u5f88\u9057\u61belast\u547d\u4ee4\u4e0d\u652f\u6301\u663e\u793a\u5e74\u4efd\uff0c\u53ea\u6709&#8221;last -t YYYYMMDDHHMMSS&#8221;\u8868\u793a\u67d0\u4e2a\u65f6\u95f4\u4e4b\u95f4\u7684\u767b\u5f55\uff0c\u6211<br \/>\n# \u53ea\u80fd\u7528\u6700\u7b28\u7684\u65b9\u6cd5\u4e86\uff0c\u5bf9\u6bd4\u4eca\u5929\u4e4b\u524d\u548c\u4eca\u5e74\u5143\u65e6\u4e4b\u524d\uff08\u6216\u8005\u53bb\u5e74\u4e4b\u524d\u548c\u524d\u5e74\u4e4b\u524d\u2026\u2026\uff09\u67d0\u4e2a\u7528\u6237<br \/>\n# \u767b\u5f55\u6b21\u6570\uff0c\u5982\u679c\u767b\u5f55\u7edf\u8ba1\u6b21\u6570\u6709\u53d8\u5316\uff0c\u5219\u8bf4\u660e\u6700\u8fd1\u4e00\u6b21\u767b\u5f55\u662f\u4eca\u5e74\u3002<br \/>\nusername=$1<br \/>\n: ${username:=&#8221;`whoami`&#8221;}<br \/>\nthisYear=$(date +%Y)<br \/>\noldesYear=$(last | tail -n1 | awk &#8216;{print $NF}&#8217;)<br \/>\nwhile(( $thisYear &gt;= $oldesYear));do<br \/>\nloginBeforeToday=$(last $username | grep $username | wc -l)<br \/>\nloginBeforeNewYearsDayOfThisYear=$(last $username -t $thisYear&#8221;0101000000&#8243; | grep $username | wc -l)<br \/>\nif [ $loginBeforeToday -eq 0 ];then<br \/>\necho &#8220;\u4ece\u672a\u767b\u5f55\u8fc7&#8221;<br \/>\nbreak<br \/>\nelif [ $loginBeforeToday -gt $loginBeforeNewYearsDayOfThisYear ];then<br \/>\nlastDateTime=$(last -i $username | head -n1 | awk &#8216;{for(i=4;i&lt;(NF-2);i++)printf&#8221;%s &#8220;,$i}&#8217;)&#8221; $thisYear&#8221; #\u683c\u5f0f\u5982: Sat Nov 2 20:33 2015<br \/>\nlastDateTime=$(date &#8220;+%Y-%m-%d %H:%M:%S&#8221; -d &#8220;$lastDateTime&#8221;)<br \/>\necho &#8220;$lastDateTime&#8221;<br \/>\nbreak<br \/>\nelse<br \/>\nthisYear=$((thisYear-1))<br \/>\nfi<br \/>\ndone<\/p>\n<p>}<\/p>\n<p>function getUserStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u7528\u6237\u68c0\u67e5 ############################&#8221;<br \/>\n# 23\u3001\/etc\/passwd \u6700\u540e\u4fee\u6539\u65f6\u95f4<br \/>\npwdfile=&#8221;$(cat \/etc\/passwd)&#8221;<br \/>\nModify=$(stat \/etc\/passwd | grep Modify | tr &#8216;.&#8217; &#8216; &#8216; | awk &#8216;{print $2,$3}&#8217;)<\/p>\n<p>echo &#8220;\/etc\/passwd \u6700\u540e\u4fee\u6539\u65f6\u95f4\uff1a$Modify ($(getHowLongAgo $Modify))&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u7279\u6743\u7528\u6237&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8211;&#8221;<br \/>\nRootUser=&#8221;&#8221;<br \/>\nfor user in $(echo &#8220;$pwdfile&#8221; | awk -F: &#8216;{print $1}&#8217;);do<br \/>\nif [ $(id -u $user) -eq 0 ];then<br \/>\necho &#8220;$user&#8221;<br \/>\nRootUser=&#8221;$RootUser,$user&#8221;<br \/>\nfi<br \/>\ndone<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u7528\u6237\u5217\u8868&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8211;&#8221;<br \/>\nUSERs=0<br \/>\necho &#8220;$(<br \/>\necho &#8220;\u7528\u6237\u540d UID GID HOME SHELL \u6700\u540e\u4e00\u6b21\u767b\u5f55&#8221;<br \/>\nfor shell in $(grep -v &#8220;\/sbin\/nologin&#8221; \/etc\/shells);do<br \/>\nfor username in $(grep &#8220;$shell&#8221; \/etc\/passwd| awk -F: &#8216;{print $1}&#8217;);do<br \/>\nuserLastLogin=&#8221;$(getUserLastLogin $username)&#8221;<br \/>\necho &#8220;$pwdfile&#8221; | grep -w &#8220;$username&#8221; |grep -w &#8220;$shell&#8221;| awk -F: -v lastlogin=&#8221;$(echo &#8220;$userLastLogin&#8221; | tr &#8216; &#8216; &#8216;_&#8217;)&#8221; &#8216;{print $1,$3,$4,$6,$7,lastlogin}&#8217;<br \/>\ndone<br \/>\nlet USERs=USERs+$(echo &#8220;$pwdfile&#8221; | grep &#8220;$shell&#8221;| wc -l)<br \/>\ndone<br \/>\n)&#8221; | column -t<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u7a7a\u5bc6\u7801\u7528\u6237&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;-&#8221;<br \/>\nUSEREmptyPassword=&#8221;&#8221;<br \/>\nfor shell in $(grep -v &#8220;\/sbin\/nologin&#8221; \/etc\/shells);do<br \/>\nfor user in $(echo &#8220;$pwdfile&#8221; | grep &#8220;$shell&#8221; | cut -d: -f1);do<br \/>\nr=$(awk -F: &#8216;$2==&#8221;!!&#8221;{print $1}&#8217; \/etc\/shadow | grep -w $user)<br \/>\nif [ ! -z $r ];then<br \/>\necho $r<br \/>\nUSEREmptyPassword=&#8221;$USEREmptyPassword,&#8221;$r<br \/>\nfi<br \/>\ndone<br \/>\ndone<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u76f8\u540cID\u7684\u7528\u6237&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8221;<br \/>\nUSERTheSameUID=&#8221;&#8221;<br \/>\nUIDs=$(cut -d: -f3 \/etc\/passwd | sort | uniq -c | awk &#8216;$1&gt;1{print $2}&#8217;)<br \/>\nfor uid in $UIDs;do<br \/>\necho -n &#8220;$uid&#8221;;<br \/>\nUSERTheSameUID=&#8221;$uid&#8221;<br \/>\nr=$(awk -F: &#8216;ORS=&#8221;&#8221;;$3=='&#8221;$uid&#8221;&#8216;{print &#8220;:&#8221;,$1}&#8217; \/etc\/passwd)<br \/>\necho &#8220;$r&#8221;<br \/>\necho &#8220;&#8221;<br \/>\nUSERTheSameUID=&#8221;$USERTheSameUID $r,&#8221;<br \/>\ndone<br \/>\n# 24\u3001\u7528\u6237\u62a5\u8868\u4fe1\u606f<br \/>\nreport_USERs=&#8221;$USERs&#8221; #\u7528\u6237<br \/>\nreport_USEREmptyPassword=$(echo $USEREmptyPassword | sed &#8216;s\/^,\/\/&#8217;)<br \/>\nreport_USERTheSameUID=$(echo $USERTheSameUID | sed &#8216;s\/,$\/\/&#8217;)<br \/>\nreport_RootUser=$(echo $RootUser | sed &#8216;s\/^,\/\/&#8217;) #\u7279\u6743\u7528\u6237<br \/>\n}<\/p>\n<p>function getPasswordStatus {<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u5bc6\u7801\u68c0\u67e5 ############################&#8221;<br \/>\npwdfile=&#8221;$(cat \/etc\/passwd)&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u5bc6\u7801\u8fc7\u671f\u68c0\u67e5&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8221;<br \/>\nresult=&#8221;&#8221;<br \/>\nfor shell in $(grep -v &#8220;\/sbin\/nologin&#8221; \/etc\/shells);do<br \/>\nfor user in $(echo &#8220;$pwdfile&#8221; | grep &#8220;$shell&#8221; | cut -d: -f1);do<br \/>\nget_expiry_date=$(\/usr\/bin\/chage -l $user | grep &#8216;Password expires&#8217; | cut -d: -f2)<br \/>\nif [[ $get_expiry_date = &#8216; never&#8217; || $get_expiry_date = &#8216;never&#8217; ]];then<br \/>\nprintf &#8220;%-15s \u6c38\u4e0d\u8fc7\u671f\\n&#8221; $user<br \/>\nresult=&#8221;$result,$user:never&#8221;<br \/>\nelse<br \/>\npassword_expiry_date=$(date -d &#8220;$get_expiry_date&#8221; &#8220;+%s&#8221;)<br \/>\ncurrent_date=$(date &#8220;+%s&#8221;)<br \/>\ndiff=$(($password_expiry_date-$current_date))<br \/>\nlet DAYS=$(($diff\/(60*60*24)))<br \/>\nprintf &#8220;%-15s %s\u5929\u540e\u8fc7\u671f\\n&#8221; $user $DAYS<br \/>\nresult=&#8221;$result,$user:$DAYS days&#8221;<br \/>\nfi<br \/>\ndone<br \/>\ndone<br \/>\nreport_PasswordExpiry=$(echo $result | sed &#8216;s\/^,\/\/&#8217;)<\/p>\n<p>echo &#8220;&#8221;<br \/>\necho &#8220;\u5bc6\u7801\u7b56\u7565\u68c0\u67e5&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8221;<br \/>\ngrep -v &#8220;#&#8221; \/etc\/login.defs | grep -E &#8220;PASS_MAX_DAYS|PASS_MIN_DAYS|PASS_MIN_LEN|PASS_WARN_AGE&#8221;<\/p>\n<p>}<\/p>\n<p>function getSudoersStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ Sudoers\u68c0\u67e5 #########################&#8221;<br \/>\nconf=$(grep -v &#8220;^#&#8221; \/etc\/sudoers| grep -v &#8220;^Defaults&#8221; | sed &#8216;\/^$\/d&#8217;)<br \/>\necho &#8220;$conf&#8221;<br \/>\necho &#8220;&#8221;<br \/>\n# 25\u3001\u8fdb\u7a0b\u62a5\u8868\u4fe1\u606f<br \/>\nreport_Sudoers=&#8221;$(echo $conf | wc -l)&#8221;<br \/>\n}<\/p>\n<p>function getInstalledStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u8f6f\u4ef6\u68c0\u67e5 ############################&#8221;<br \/>\nrpm -qa &#8211;last | head | column -t<br \/>\n}<\/p>\n<p>function getProcessStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u8fdb\u7a0b\u68c0\u67e5 ############################&#8221;<br \/>\nif [ $(ps -ef | grep defunct | grep -v grep | wc -l) -ge 1 ];then<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u50f5\u5c38\u8fdb\u7a0b&#8221;;<br \/>\necho &#8220;&#8212;&#8212;&#8211;&#8221;<br \/>\nps -ef | head -n1<br \/>\nps -ef | grep defunct | grep -v grep<br \/>\nfi<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u5185\u5b58\u5360\u7528TOP10&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;-&#8221;<br \/>\necho -e &#8220;PID %MEM RSS COMMAND<br \/>\n$(ps aux | awk &#8216;{print $2, $4, $6, $11}&#8217; | sort -k3rn | head -n 10 )&#8221;| column -t<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;CPU\u5360\u7528TOP10&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8221;<br \/>\ntop b -n1 | head -17 | tail -11<br \/>\n# 26\u3001jdk\u68c0\u67e5\u62a5\u8868\u4fe1\u606f<br \/>\nreport_DefunctProsess=&#8221;$(ps -ef | grep defunct | grep -v grep|wc -l)&#8221;<br \/>\n}<\/p>\n<p>function getJDKStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ JDK\u68c0\u67e5 #############################&#8221;<br \/>\njava -version 2&gt;\/dev\/null<br \/>\nif [ $? -eq 0 ];then<br \/>\njava -version 2&gt;&amp;1<br \/>\nfi<br \/>\necho &#8220;JAVA_HOME=\\&#8221;$JAVA_HOME\\&#8221;&#8221;<br \/>\n# 27\u3001jdk\u68c0\u67e5\u62a5\u8868\u4fe1\u606f<br \/>\nreport_JDK=&#8221;$(java -version 2&gt;&amp;1 | grep version | awk &#8216;{print $1,$3}&#8217; | tr -d &#8216;&#8221;&#8216;)&#8221;<br \/>\n}<br \/>\nfunction getSyslogStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ syslog\u68c0\u67e5 ##########################&#8221;<br \/>\necho &#8220;\u670d\u52a1\u72b6\u6001\uff1a$(getState rsyslog)&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\/etc\/rsyslog.conf&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8221;<br \/>\ncat \/etc\/rsyslog.conf 2&gt;\/dev\/null | grep -v &#8220;^#&#8221; | grep -v &#8220;^\\\\$&#8221; | sed &#8216;\/^$\/d&#8217; | column -t<br \/>\n# 28\u3001\u9632\u706b\u5899\u62a5\u8868\u4fe1\u606f<br \/>\nreport_Syslog=&#8221;$(getState rsyslog)&#8221;<br \/>\n}<br \/>\nfunction getFirewallStatus(){<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ \u9632\u706b\u5899\u68c0\u67e5 ##########################&#8221;<br \/>\n# 29\u3001\u9632\u706b\u5899\u72b6\u6001\uff0c\u7b56\u7565\u7b49<br \/>\nif [[ $centosVersion &lt; 7 ]];then<br \/>\n\/etc\/init.d\/iptables status &gt;\/dev\/null 2&gt;&amp;1<br \/>\nstatus=$?<br \/>\nif [ $status -eq 0 ];then<br \/>\ns=&#8221;active&#8221;<br \/>\nelif [ $status -eq 3 ];then<br \/>\ns=&#8221;inactive&#8221;<br \/>\nelif [ $status -eq 4 ];then<br \/>\ns=&#8221;permission denied&#8221;<br \/>\nelse<br \/>\ns=&#8221;unknown&#8221;<br \/>\nfi<br \/>\nelse<br \/>\ns=&#8221;$(getState iptables)&#8221;<br \/>\nfi<br \/>\necho &#8220;iptables: $s&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\/etc\/sysconfig\/iptables&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8221;<br \/>\ncat \/etc\/sysconfig\/iptables 2&gt;\/dev\/null<br \/>\n# 30\u3001\u9632\u706b\u5899\u62a5\u8868\u4fe1\u606f<br \/>\nreport_Firewall=&#8221;$s&#8221;<br \/>\n}<\/p>\n<p>function getSNMPStatus(){<br \/>\n# 31\u3001SNMP\u670d\u52a1\u72b6\u6001\uff0c\u914d\u7f6e\u7b49<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ SNMP\u68c0\u67e5 ############################&#8221;<br \/>\nstatus=&#8221;$(getState snmpd)&#8221;<br \/>\necho &#8220;\u670d\u52a1\u72b6\u6001\uff1a$status&#8221;<br \/>\necho &#8220;&#8221;<br \/>\nif [ -e \/etc\/snmp\/snmpd.conf ];then<br \/>\necho &#8220;\/etc\/snmp\/snmpd.conf&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8221;<br \/>\ncat \/etc\/snmp\/snmpd.conf 2&gt;\/dev\/null | grep -v &#8220;^#&#8221; | sed &#8216;\/^$\/d&#8217;<br \/>\nfi<br \/>\n# 32\u3001SNMP\u62a5\u8868\u4fe1\u606f<br \/>\nreport_SNMP=&#8221;$(getState snmpd)&#8221;<br \/>\n}<br \/>\nfunction getState(){<br \/>\nif [[ $centosVersion &lt; 7 ]];then<br \/>\nif [ -e &#8220;\/etc\/init.d\/$1&#8221; ];then<br \/>\nif [ `\/etc\/init.d\/$1 status 2&gt;\/dev\/null | grep -E &#8220;is running|\u6b63\u5728\u8fd0\u884c&#8221; | wc -l` -ge 1 ];then<br \/>\nr=&#8221;active&#8221;<br \/>\nelse<br \/>\nr=&#8221;inactive&#8221;<br \/>\nfi<br \/>\nelse<br \/>\nr=&#8221;unknown&#8221;<br \/>\nfi<br \/>\nelse<br \/>\n#CentOS 7+<br \/>\nr=&#8221;$(systemctl is-active $1 2&gt;&amp;1)&#8221;<br \/>\nfi<br \/>\necho &#8220;$r&#8221;<br \/>\n}<br \/>\nfunction getSSHStatus(){<br \/>\n# 33\u3001SSHD\u670d\u52a1\u72b6\u6001\uff0c\u914d\u7f6e,\u53d7\u4fe1\u4efb\u4e3b\u673a\u7b49<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ SSH\u68c0\u67e5 #############################&#8221;<br \/>\n# 34\u3001\u68c0\u67e5\u53d7\u4fe1\u4efb\u4e3b\u673a<br \/>\npwdfile=&#8221;$(cat \/etc\/passwd)&#8221;<br \/>\necho &#8220;\u670d\u52a1\u72b6\u6001\uff1a$(getState sshd)&#8221;<br \/>\nProtocol_Version=$(cat \/etc\/ssh\/sshd_config | grep Protocol | awk &#8216;{print $2}&#8217;)<br \/>\necho &#8220;SSH\u534f\u8bae\u7248\u672c\uff1a$Protocol_Version&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\u4fe1\u4efb\u4e3b\u673a&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8211;&#8221;<br \/>\nauthorized=0<br \/>\nfor user in $(echo &#8220;$pwdfile&#8221; | grep \/bin\/bash | awk -F: &#8216;{print $1}&#8217;);do<br \/>\nauthorize_file=$(echo &#8220;$pwdfile&#8221; | grep -w $user | awk -F: &#8216;{printf $6&#8243;\/.ssh\/authorized_keys&#8221;}&#8217;)<br \/>\nauthorized_host=$(cat $authorize_file 2&gt;\/dev\/null | awk &#8216;{print $3}&#8217; | tr &#8216;\\n&#8217; &#8216;,&#8217; | sed &#8216;s\/,$\/\/&#8217;)<br \/>\nif [ ! -z $authorized_host ];then<br \/>\necho &#8220;$user \u6388\u6743 \\&#8221;$authorized_host\\&#8221; \u65e0\u5bc6\u7801\u8bbf\u95ee&#8221;<br \/>\nfi<br \/>\nlet authorized=authorized+$(cat $authorize_file 2&gt;\/dev\/null | awk &#8216;{print $3}&#8217;|wc -l)<br \/>\ndone<\/p>\n<p>echo &#8220;&#8221;<br \/>\necho &#8220;\u662f\u5426\u5141\u8bb8ROOT\u8fdc\u7a0b\u767b\u5f55&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8221;<br \/>\nconfig=$(cat \/etc\/ssh\/sshd_config | grep PermitRootLogin)<br \/>\nfirstChar=${config:0:1}<br \/>\nif [ $firstChar == &#8220;#&#8221; ];then<br \/>\nPermitRootLogin=&#8221;yes&#8221; #\u9ed8\u8ba4\u662f\u5141\u8bb8ROOT\u8fdc\u7a0b\u767b\u5f55\u7684<br \/>\nelse<br \/>\nPermitRootLogin=$(echo $config | awk &#8216;{print $2}&#8217;)<br \/>\nfi<br \/>\necho &#8220;PermitRootLogin $PermitRootLogin&#8221;<\/p>\n<p>echo &#8220;&#8221;<br \/>\necho &#8220;\/etc\/ssh\/sshd_config&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8221;<br \/>\ncat \/etc\/ssh\/sshd_config | grep -v &#8220;^#&#8221; | sed &#8216;\/^$\/d&#8217;<\/p>\n<p># 35\u3001\u4fe1\u4efb\u4e3b\u673a\u62a5\u8868\u4fe1\u606f<br \/>\nreport_SSHAuthorized=&#8221;$authorized&#8221; #SSH\u4fe1\u4efb\u4e3b\u673a<br \/>\nreport_SSHDProtocolVersion=&#8221;$Protocol_Version&#8221; #SSH\u534f\u8bae\u7248\u672c<br \/>\nreport_SSHDPermitRootLogin=&#8221;$PermitRootLogin&#8221; #\u5141\u8bb8root\u8fdc\u7a0b\u767b\u5f55<br \/>\n}<br \/>\nfunction getNTPStatus(){<br \/>\n# 36\u3001NTP\u670d\u52a1\u72b6\u6001\uff0c\u5f53\u524d\u65f6\u95f4\uff0c\u914d\u7f6e\u7b49<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;############################ NTP\u68c0\u67e5 #############################&#8221;<br \/>\nif [ -e \/etc\/ntp.conf ];then<br \/>\necho &#8220;\u670d\u52a1\u72b6\u6001\uff1a$(getState ntpd)&#8221;<br \/>\necho &#8220;&#8221;<br \/>\necho &#8220;\/etc\/ntp.conf&#8221;<br \/>\necho &#8220;&#8212;&#8212;&#8212;&#8212;-&#8221;<br \/>\ncat \/etc\/ntp.conf 2&gt;\/dev\/null | grep -v &#8220;^#&#8221; | sed &#8216;\/^$\/d&#8217;<br \/>\nfi<br \/>\n# 37\u3001NTP\u62a5\u8868\u4fe1\u606f<br \/>\nreport_NTP=&#8221;$(getState ntpd)&#8221;<br \/>\n}<br \/>\nfunction uploadHostDailyCheckReport(){<br \/>\njson=&#8221;{<br \/>\n\\&#8221;DateTime\\&#8221;:\\&#8221;$report_DateTime\\&#8221;,<br \/>\n\\&#8221;Hostname\\&#8221;:\\&#8221;$report_Hostname\\&#8221;,<br \/>\n\\&#8221;OSRelease\\&#8221;:\\&#8221;$report_OSRelease\\&#8221;,<br \/>\n\\&#8221;Kernel\\&#8221;:\\&#8221;$report_Kernel\\&#8221;,<br \/>\n\\&#8221;Language\\&#8221;:\\&#8221;$report_Language\\&#8221;,<br \/>\n\\&#8221;LastReboot\\&#8221;:\\&#8221;$report_LastReboot\\&#8221;,<br \/>\n\\&#8221;Uptime\\&#8221;:\\&#8221;$report_Uptime\\&#8221;,<br \/>\n\\&#8221;CPUs\\&#8221;:\\&#8221;$report_CPUs\\&#8221;,<br \/>\n\\&#8221;CPUType\\&#8221;:\\&#8221;$report_CPUType\\&#8221;,<br \/>\n\\&#8221;Arch\\&#8221;:\\&#8221;$report_Arch\\&#8221;,<br \/>\n\\&#8221;MemTotal\\&#8221;:\\&#8221;$report_MemTotal\\&#8221;,<br \/>\n\\&#8221;MemFree\\&#8221;:\\&#8221;$report_MemFree\\&#8221;,<br \/>\n\\&#8221;MemUsedPercent\\&#8221;:\\&#8221;$report_MemUsedPercent\\&#8221;,<br \/>\n\\&#8221;DiskTotal\\&#8221;:\\&#8221;$report_DiskTotal\\&#8221;,<br \/>\n\\&#8221;DiskFree\\&#8221;:\\&#8221;$report_DiskFree\\&#8221;,<br \/>\n\\&#8221;DiskUsedPercent\\&#8221;:\\&#8221;$report_DiskUsedPercent\\&#8221;,<br \/>\n\\&#8221;InodeTotal\\&#8221;:\\&#8221;$report_InodeTotal\\&#8221;,<br \/>\n\\&#8221;InodeFree\\&#8221;:\\&#8221;$report_InodeFree\\&#8221;,<br \/>\n\\&#8221;InodeUsedPercent\\&#8221;:\\&#8221;$report_InodeUsedPercent\\&#8221;,<br \/>\n\\&#8221;IP\\&#8221;:\\&#8221;$report_IP\\&#8221;,<br \/>\n\\&#8221;MAC\\&#8221;:\\&#8221;$report_MAC\\&#8221;,<br \/>\n\\&#8221;Gateway\\&#8221;:\\&#8221;$report_Gateway\\&#8221;,<br \/>\n\\&#8221;DNS\\&#8221;:\\&#8221;$report_DNS\\&#8221;,<br \/>\n\\&#8221;Listen\\&#8221;:\\&#8221;$report_Listen\\&#8221;,<br \/>\n\\&#8221;Selinux\\&#8221;:\\&#8221;$report_Selinux\\&#8221;,<br \/>\n\\&#8221;Firewall\\&#8221;:\\&#8221;$report_Firewall\\&#8221;,<br \/>\n\\&#8221;USERs\\&#8221;:\\&#8221;$report_USERs\\&#8221;,<br \/>\n\\&#8221;USEREmptyPassword\\&#8221;:\\&#8221;$report_USEREmptyPassword\\&#8221;,<br \/>\n\\&#8221;USERTheSameUID\\&#8221;:\\&#8221;$report_USERTheSameUID\\&#8221;,<br \/>\n\\&#8221;PasswordExpiry\\&#8221;:\\&#8221;$report_PasswordExpiry\\&#8221;,<br \/>\n\\&#8221;RootUser\\&#8221;:\\&#8221;$report_RootUser\\&#8221;,<br \/>\n\\&#8221;Sudoers\\&#8221;:\\&#8221;$report_Sudoers\\&#8221;,<br \/>\n\\&#8221;SSHAuthorized\\&#8221;:\\&#8221;$report_SSHAuthorized\\&#8221;,<br \/>\n\\&#8221;SSHDProtocolVersion\\&#8221;:\\&#8221;$report_SSHDProtocolVersion\\&#8221;,<br \/>\n\\&#8221;SSHDPermitRootLogin\\&#8221;:\\&#8221;$report_SSHDPermitRootLogin\\&#8221;,<br \/>\n\\&#8221;DefunctProsess\\&#8221;:\\&#8221;$report_DefunctProsess\\&#8221;,<br \/>\n\\&#8221;SelfInitiatedService\\&#8221;:\\&#8221;$report_SelfInitiatedService\\&#8221;,<br \/>\n\\&#8221;SelfInitiatedProgram\\&#8221;:\\&#8221;$report_SelfInitiatedProgram\\&#8221;,<br \/>\n\\&#8221;RuningService\\&#8221;:\\&#8221;$report_RuningService\\&#8221;,<br \/>\n\\&#8221;Crontab\\&#8221;:\\&#8221;$report_Crontab\\&#8221;,<br \/>\n\\&#8221;Syslog\\&#8221;:\\&#8221;$report_Syslog\\&#8221;,<br \/>\n\\&#8221;SNMP\\&#8221;:\\&#8221;$report_SNMP\\&#8221;,<br \/>\n\\&#8221;NTP\\&#8221;:\\&#8221;$report_NTP\\&#8221;,<br \/>\n\\&#8221;JDK\\&#8221;:\\&#8221;$report_JDK\\&#8221;<br \/>\n}&#8221;<br \/>\n# 38\u3001echo &#8220;$json&#8221;<br \/>\ncurl -l -H &#8220;Content-type: application\/json&#8221; -X POST -d &#8220;$json&#8221; &#8220;$uploadHostDailyCheckReportApi&#8221; 2&gt;\/dev\/null<br \/>\n}<br \/>\nfunction getchage_file_24h()<br \/>\n{<br \/>\necho &#8220;############################ \u6587\u4ef6\u68c0\u67e5 #############################&#8221;<br \/>\ncheck2=$(find \/ -name &#8216;*.sh&#8217; -mtime -1)<br \/>\ncheck21=$(find \/ -name &#8216;*.asp&#8217; -mtime -1)<br \/>\ncheck22=$(find \/ -name &#8216;*.php&#8217; -mtime -1)<br \/>\ncheck23=$(find \/ -name &#8216;*.aspx&#8217; -mtime -1)<br \/>\ncheck24=$(find \/ -name &#8216;*.jsp&#8217; -mtime -1)<br \/>\ncheck25=$(find \/ -name &#8216;*.html&#8217; -mtime -1)<br \/>\ncheck26=$(find \/ -name &#8216;*.htm&#8217; -mtime -1)<br \/>\ncheck9=$(find \/ -name core -exec ls -l {} \\;)<br \/>\ncheck10=$(cat \/etc\/crontab)<br \/>\ncheck12=$(ls -alt \/usr\/bin | head -10)<br \/>\ncat &lt;&lt;EOF<br \/>\n############################\u67e5\u770b\u6240\u6709\u88ab\u4fee\u6539\u8fc7\u7684\u6587\u4ef6\u8fd4\u56de\u6700\u8fd124\u5c0f\u65f6\u5185\u7684############################<br \/>\n${check2}<br \/>\n${check21}<br \/>\n${check22}<br \/>\n${check23}<br \/>\n${check24}<br \/>\n${check25}<br \/>\n${check26}<br \/>\n${line}<br \/>\n############################\u68c0\u67e5\u5b9a\u65f6\u6587\u4ef6\u7684\u5b8c\u6574\u6027############################<br \/>\n${check10}<br \/>\n${line}<\/p>\n<p>############################\u67e5\u770b\u7cfb\u7edf\u547d\u4ee4\u662f\u5426\u88ab\u66ff\u6362############################<br \/>\n${check12}<br \/>\n${line}<br \/>\nEOF<br \/>\n}<br \/>\nfunction check(){<br \/>\nversion<br \/>\ngetSystemStatus<br \/>\ngetCpuStatus<br \/>\ngetMemStatus<br \/>\ngetDiskStatus<br \/>\ngetNetworkStatus<br \/>\ngetListenStatus<br \/>\ngetProcessStatus<br \/>\ngetServiceStatus<br \/>\ngetAutoStartStatus<br \/>\ngetLoginStatus<br \/>\ngetCronStatus<br \/>\ngetUserStatus<br \/>\ngetPasswordStatus<br \/>\ngetSudoersStatus<br \/>\ngetJDKStatus<br \/>\ngetFirewallStatus<br \/>\ngetSSHStatus<br \/>\ngetSyslogStatus<br \/>\ngetSNMPStatus<br \/>\ngetNTPStatus<br \/>\ngetInstalledStatus<br \/>\ngetchage_file_24h<br \/>\n}<\/p>\n<p># 39\u3001\u6267\u884c\u68c0\u67e5\u5e76\u4fdd\u5b58\u68c0\u67e5\u7ed3\u679c<br \/>\ncheck &gt; $RESULTFILE<\/p>\n<p>echo &#8220;\u68c0\u67e5\u7ed3\u679c\uff1a$RESULTFILE&#8221;<br \/>\necho -e &#8220;`date &#8220;+%Y-%m-%d %H:%M:%S&#8221;` \u963f\u91cc\u4e91PHP\u4f01\u4e1a\u5e73\u53f0\u5de1\u68c0\u62a5\u544a&#8221; | mail -a $RESULTFILE -s &#8220;\u963f\u91cc\u4e91PHP\u4f01\u4e1a\u5e73\u53f0\u5de1\u68c0\u62a5\u544a&#8221; fengmm@shait.com.cn<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash #1\u3001\u4e3b\u673a\u4fe1\u606f\u6bcf\u65e5\u5de1\u68c0 IPADDR=$(ifconfig eth0|grep &#038;#8 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":671,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-668","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=668"}],"version-history":[{"count":3,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions"}],"predecessor-version":[{"id":672,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/posts\/668\/revisions\/672"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=\/wp\/v2\/media\/671"}],"wp:attachment":[{"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bunnyism.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}