Linux 巡检脚本大全

Linux 巡检脚本

#!/bin/bash

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
source /etc/profile

[ KaTeX parse error: Expected 'EOF', got '&' at position 17: …id -u) -gt 0 ] &̲& echo "请用root用…(awk ‘{print $(NF-1)}’ /etc/redhat-release)
VERSION=date +%F

#日志相关
PROGPATH=echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'
[ -f KaTeX parse error: Expected 'EOF', got '&' at position 12: PROGPATH ] &̲& PROGPATH="." …PROGPATH/log"
[ -e $LOGPATH ] || mkdir L O G P A T H R E S U L T F I L E = " LOGPATH RESULTFILE=" LOGPATHRESULTFILE="LOGPATH/HostDailyCheck-hostname-date +%Y%m%d.txt"

#定义报表的全局变量
report_DateTime=""
report_Hostname=""
report_OSRelease=""
report_Kernel=""
report_Language=""
report_LastReboot=""
report_Uptime=""
report_CPUs=""
report_CPUType=""
report_Arch=""
report_MemTotal=""
report_MemFree=""
report_MemUsedPercent=""
report_DiskTotal=""
report_DiskFree=""
report_DiskUsedPercent=""
report_InodeTotal=""
report_InodeFree=""
report_InodeUsedPercent=""
report_IP=""
report_MAC=""
report_Gateway=""
report_DNS=""
report_Listen=""
report_Selinux=""
report_Firewall=""
report_USERs=""
report_USEREmptyPassword=""
report_USERTheSameUID=""
report_PasswordExpiry=""
report_RootUser=""
report_Sudoers=""
report_SSHAuthorized=""
report_SSHDProtocolVersion=""
report_SSHDPermitRootLogin=""
report_DefunctProsess=""
report_SelfInitiatedService=""
report_SelfInitiatedProgram=""
report_RuningService=""
report_Crontab=""
report_Syslog=""
report_SNMP=""
report_NTP=""
report_JDK=""
function version(){
echo “”
echo “”
echo “系统巡检脚本:Version $VERSION”
}

function getCpuStatus(){
echo “”
echo -e “\033[33mCPU检查\033[0m”
Physical_CPUs= ( g r e p " p h y s i c a l i d " / p r o c / c p u i n f o ∣ s o r t ∣ u n i q ∣ w c − l ) V i r t C P U s = (grep "physical id" /proc/cpuinfo| sort | uniq | wc -l) Virt_CPUs= (grep"physicalid"/proc/cpuinfosortuniqwcl)VirtCPUs=(grep “processor” /proc/cpuinfo | wc -l)
CPU_Kernels=$(grep “cores” /proc/cpuinfo|uniq| awk -F ': ’ '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') CPU_Type…(grep “model name” /proc/cpuinfo | awk -F ': ’ '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲' | sort | uniq…(uname -m)
echo “物理CPU个数: P h y s i c a l C P U s " e c h o " 逻 辑 C P U 个 数 : Physical_CPUs" echo "逻辑CPU个数: PhysicalCPUs"echo"CPU:Virt_CPUs”
echo “每CPU核心数: C P U K e r n e l s " e c h o " C P U 型 号 : CPU_Kernels" echo " CPU型号: CPUKernels"echo"CPU:CPU_Type”
echo " CPU架构:KaTeX parse error: Expected 'EOF', got '#' at position 15: CPU_Arch" #̲报表信息 report…Virt_CPUs
report_CPUType= C P U T y p e r e p o r t A r c h = CPU_Type report_Arch= CPUTypereportArch=CPU_Arch
}

function getMemStatus(){
echo “”
echo -e “\033[33m内存检查\033[0m”
if [[ KaTeX parse error: Expected 'EOF', got '#' at position 80: … -h fi #̲报表信息 MemTot…(grep MemTotal /proc/meminfo| awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') #KB Mem…(grep MemFree /proc/meminfo| awk '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') #KB l…(awk “BEGIN {if(KaTeX parse error: Can't use function '\"' in math mode at position 37: …00}else{printf \̲"̲%.2f\",MemUsed100/KaTeX parse error: Expected 'EOF', got '}' at position 9: MemTotal}̲}") report_…((MemTotal/1024))"“MB”
report_MemFree=" ( ( M e m F r e e / 1024 ) ) " " M B " r e p o r t M e m U s e d P e r c e n t = " ((MemFree/1024))""MB" report_MemUsedPercent=" ((MemFree/1024))""MB"reportMemUsedPercent="(awk "BEGIN {if(KaTeX parse error: Can't use function '\"' in math mode at position 37: …00}else{printf \̲"̲%.2f\",MemUsed
100/$MemTotal}}”)""%"
}

function getDiskStatus(){
echo “”
echo -e “\033[33m磁盘检查\033[0m”
df -hiP | sed ‘s/Mounted on/Mounted/’> /tmp/inode
df -hTP | sed ‘s/Mounted on/Mounted/’> /tmp/disk
join /tmp/disk /tmp/inode | awk '{print $1,$2,"|",$3,$4,$5,$6,"|",$8,$9,$10,$11,"|",KaTeX parse error: Expected 'EOF', got '}' at position 3: 12}̲'| column -t …(df -TP | sed ‘1d’ | awk 'KaTeX parse error: Expected 'EOF', got '#' at position 21: …mpfs"{print}') #̲KB disktota…(echo “$diskdata” | awk '{total+=KaTeX parse error: Expected 'EOF', got '}' at position 2: 3}̲END{print total…(echo “$diskdata” | awk '{total+=KaTeX parse error: Expected 'EOF', got '}' at position 2: 4}̲END{print total…((disktotal-diskused)) #KB
diskusedpercent=$(echo $disktotal $diskused | awk '{if($10){printf 100}else{printf “%.2f”,$2*100/KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}̲}') inodeda…(df -iTP | sed ‘1d’ | awk ' 2 ! = " t m p f s " p r i n t ′ ) i n o d e t o t a l = 2!="tmpfs"{print}') inodetotal= 2!="tmpfs"print)inodetotal=(echo “$inodedata” | awk '{total+=KaTeX parse error: Expected 'EOF', got '}' at position 2: 3}̲END{print total…(echo “$inodedata” | awk '{total+=KaTeX parse error: Expected 'EOF', got '}' at position 2: 4}̲END{print total…((inodetotal-inodeused))
inodeusedpercent=$(echo $inodetotal $inodeused | awk '{if($1
0){printf 100}else{printf “%.2f”,$2*100/KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}̲}') report_…((disktotal/1024/1024))“GB”
report_DiskFree= ( ( d i s k f r e e / 1024 / 1024 ) ) " G B " r e p o r t D i s k U s e d P e r c e n t = " ((diskfree/1024/1024))"GB" report_DiskUsedPercent=" ((diskfree/1024/1024))"GB"reportDiskUsedPercent="diskusedpercent""%"
report_InodeTotal= ( ( i n o d e t o t a l / 1000 ) ) " K " r e p o r t I n o d e F r e e = ((inodetotal/1000))"K" report_InodeFree= ((inodetotal/1000))"K"reportInodeFree=((inodefree/1000))“K”
report_InodeUsedPercent="$inodeusedpercent""%"

}

function getSystemStatus(){
echo “”
echo -e “\033[33m*******************************************************系统检查 ******************************************************\033[0m"
if [ -e /etc/sysconfig/i18n ];then
default_LANG="$(grep “LANG=” /etc/sysconfig/i18n | grep -v “^#” | awk -F ‘"’ '{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲')" else …LANG
fi
export LANG=“en_US.UTF-8”
Release= ( c a t / e t c / r e d h a t − r e l

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值