CentOS7.X系统巡检脚本
Posted 有暗香盈袖c
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7.X系统巡检脚本相关的知识,希望对你有一定的参考价值。
CentOS7.x 系统巡检脚本
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 " 33[33m*******************************************************CPU检查******************************************************* 33[0m"
76 Physical_CPUs=$(grep "physical id" /proc/cpuinfo| sort | uniq | wc -l)
77 Virt_CPUs=$(grep "processor" /proc/cpuinfo | wc -l)
78 CPU_Kernels=$(grep "cores" /proc/cpuinfo|uniq| awk -F ': ' '{print $2}')
79 CPU_Type=$(grep "model name" /proc/cpuinfo | awk -F ': ' '{print $2}' | sort | uniq)
80 CPU_Arch=$(uname -m)
81 echo "物理CPU个数:$Physical_CPUs"
82 echo "逻辑CPU个数:$Virt_CPUs"
83 echo "每CPU核心数:$CPU_Kernels"
84 echo " CPU型号:$CPU_Type"
85 echo " CPU架构:$CPU_Arch"
86 #报表信息
87 report_CPUs=$Virt_CPUs
88 report_CPUType=$CPU_Type
89 report_Arch=$CPU_Arch
90}
91function getMemStatus(){
92 echo ""
93 echo -e " 33[33m*******************************************************内存检查******************************************************* 33[0m"
94 if [[ $centosVersion < 7 ]];then
95 free -mo
96 else
97 free -h
98 fi
99 #报表信息
100 MemTotal=$(grep MemTotal /proc/meminfo| awk '{print $2}') #KB
101 MemFree=$(grep MemFree /proc/meminfo| awk '{print $2}') #KB
102 let MemUsed=MemTotal-MemFree
103 MemPercent=$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf "%.2f",$MemUsed*100/$MemTotal}}")
104 report_MemTotal="$((MemTotal/1024))""MB"
105 report_MemFree="$((MemFree/1024))""MB"
106 report_MemUsedPercent="$(awk "BEGIN {if($MemTotal==0){printf 100}else{printf "%.2f",$MemUsed*100/$MemTotal}}")""%"
107}
108function getDiskStatus(){
109 echo ""
110 echo -e "