巡检脚本
1#!/bin/bash
2##############################################################
3# File Name: 1.sh
4# Version: V1.0
5# Author:
6# Organization:
7# Created Time : date
8# Description:
9##############################################################
10export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
11source /etc/profile
12[ $(id -u) -gt 0 ] && echo "请用root用户执行此脚本!" && exit 1
13#uploadHostDailyCheckApi="http://10.0.0.1:8080/api/uploadHostDailyCheck"
14#uploadHostDailyCheckReportApi="http://10.0.0.1:8080/api/uploadHostDailyCheckReport"
15centosVersion=$(awk '{print $(NF-1)}' /etc/redhat-release)
16VERSION=`date +%F`
17#日志相关
18PROGPATH=`echo $0 | sed -e 's,[\/][^\/][^\/]*$,,'`
19[ -f $PROGPATH ] && PROGPATH="."
20LOGPATH="$PROGPATH/log"
21[ -e $LOGPATH ] || mkdir $LOGPATH
22RESULTFILE="$LOGPATH/HostDailyCheck-`hostname`-`date +%Y%m%d`.txt"
23#定义报表的全局变量
24report_DateTime=""
25report_Hostname=""
26report_OSRelease=""
27report_Kernel=""
28report_Language=""
29report_LastReboot=""
30report_Uptime=""
31report_CPUs=""
32report_CPUType=""
33report_Arch=""
34report_MemTotal=""
35report_MemFree=""
36report_MemUsedPercent=""
37report_DiskTotal=""
38report_DiskFree=""
39report_DiskUsedPercent=""
40report_InodeTotal=""
41report_InodeFree=""
42report_InodeUsedPercent=""
43report_IP=""
44report_MAC=""
45report_Gateway=""
46report_DNS=""
47report_Listen=""
48report_Selinux=""
49report_Firewall=""
50report_USERs=""
51report_USEREmptyPassword=""
52report_USERTheSameUID=""
53report_PasswordExpiry=""
54report_RootUser=""
55report_Sudoers=""
56report_SSHAuthorized=""
57report_SSHDProtocolVersion=""
58report_SSHDPermitRootLogin=""
59report_DefunctProsess=""
60report_SelfInitiatedService=""
61report_SelfInitiatedProgram=""
62report_RuningService=""
63report_Crontab=""
64report_Syslog=""
65report_SNMP=""
66report_NTP=""
67report_JDK=""
68function version(){
69 echo ""
70 echo ""
71 echo "系统巡检脚本:Version $VERSION"
72}
73function getCpuStatus(){
74 echo ""
75 echo -e "