时间:2021-05-22
核心代码:
#!/bin/bashcheck_process(){tolprocess=`ps auxf|grep DisplayMa[nager]|wc -l`#if [ "$tolprocess" -lt "1" ];thenif [ "$tolprocess" -ge "1" ];then echo 'process ok'else echo 'fail'fi}check_log(){if [ -e /etc/syslog-ng/syslog-ng.conf ];then conlog=`cat '/etc/syslog-ng/syslog-ng.conf'|grep "10.70.72.253"|wc -l` if [ "$conlog" -ge "1" ];then echo 'syslog-ng ok' fielif [ -e /etc/syslog.conf ];then conlog=`cat '/etc/syslog.conf'|grep "10.70.72.253"|wc -l` if [ "$conlog" -ge "1" ];then echo 'syslog ok' fielse echo 'log not find or error'fi}check_cpuidle(){mincpu=`sar -u 2 10|grep all|awk '{print $NF}'|sort -nr|tail -1`if [ $(echo "${mincpu} < 20" | bc) = 1 ];then#if [ "$mincpu" -le "20" ];then echo 'cpu idle is less than 20% ,please check'else echo 'cpu idle is more than 20%, it is ok 'fi}check_mem(){vmstat 2 10 }check_disk(){chkdsk=`fdisk -l|egrep 'failed|unsynced|unavailable'|wc -l`if [ "$chkdsk" -ge "1" ];then echo 'fdisk check ok 'else echo 'fdisk check find error,please check your disk 'fi}check_io(){util=`sar -d 2 10|egrep -v 'x86|^$|await'|awk '{print $NF}'|sort -nr|tail -1`await=`sar -d 2 10|egrep -v 'x86|^$|await'|awk '{print $(NF-2)}'|sort -nr|tail -1`if [ $(echo "${util} < 80" | bc) = 1 ] && [ $(echo "${await} < 100" | bc) = 1 ] ;then echo 'disk io check is fine'else echo 'disk io use too high 'fi}check_swap(){tolswap=`cat /proc/meminfo|grep SwapTotal|awk '{print $2}'`#awk '/SwapTotal/{total=$2}/SwapFree/{free=$2}END{print (total-free)/1024}' /proc/meminfo useswap=`awk '/SwapTotal/{total=$2}/SwapFree/{free=$2}END{print (total-free)}' /proc/meminfo `util=`awk 'BEGIN{printf "%.1f\n",'$useswap'/'$tolswap'}'`if [ $(echo "${util} < 0.3" | bc) = 1 ] || [ $(echo "${useswap} < 1024" | bc) = 1 ] ;then echo 'swap use is ok 'else echo "useswap: $useswap kb, swap util is $util"fi}check_dmesg(){chkdm=`dmesg |egrep 'scsi reset|file system full'|wc -l`if [ "$chkdm" -ge "1" ];then echo 'dmesg test ok 'else echo 'dmesg check find error 'fi}check_boot(){chkdm=`cat /var/log/boot.msg|egrep 'scsi reset|file system full'|wc -l`if [ "$chkdm" -ge "1" ];then echo 'boot check fine 'else echo 'boot check find error 'fi}check_inode(){maxinode=`df -i|awk '{print $5}'|egrep -v 'IUse|-' |sed 's/%//g'|sort -nr|head -1`if [ $(echo "${maxinode} < 80" | bc) = 1 ];then echo 'inode check ok 'else echo 'inode used more than 80% 'fi}check_df(){dfuse=`df -HT|awk '{print $6}'|grep -v Use|sed 's/%//g'|sort -nr|head -1`if [ $(echo "${dfuse} < 80" | bc) = 1 ];then echo 'disk used is less than 80% ,it is ok !'elif [ $(echo "${dfuse} > 80" | bc) = 1 ] && [ $(echo "${dfuse} < 90" | bc) = 1 ];then echo 'warning , disk used more than 80% and less than 90% 'else echo ' Critical, disk used more than 90% 'fi}echo '################### check process ###################'check_processecho '################### check syslog ####################'check_logecho '################### check cpuidle ###################'check_cpuidleecho '################### echo memory stat ################'check_memecho '################### check fdisk #####################'check_diskecho '################### check io used ###################'check_ioecho '################### check swap used #################'check_swapecho '################### check dmesg #####################'check_dmesgecho '################### check inode #####################'check_inodeecho '################### check disk used #################'check_df保存为/system/check_linux.sh
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
最近收到一个工作要求,让我完成一个每天一次的Linux服务器巡检工作(服务器的版本为红帽6.4),不可以使用监控软件来操作。在这里,把我的巡检过程和巡检脚本放送
最近项目中有一个小需求,查找json文件中某个key或者value的路径,所以就写了一个简单的小脚本,比较粗糙。#!/usr/bin/envpython3#-*
最近需要用Python写一个小脚本,用到了一些小知识,赶紧抽空记录一下。不深但是常用。两个进度条示例,拷贝就能运行:#coding=utf-8importsys
自己写了玩的一个小脚本,百度图片下载importreimportosimportrequestsimporthashlibdefdowmloadPic(html
这里简单介绍一个自己写的检测某个进程是否存在的bash小脚本。直接上代码。复制代码代码如下:#!/bin/bashps_out=`ps-ef|grep$1|gr