您好,欢迎来到爱go旅游网。
搜索
您的当前位置:首页Shell文件大小监控脚本

Shell文件大小监控脚本

来源:爱go旅游网
Shell⽂件⼤⼩监控脚本

#! /bin/bash

#This script can be used to monitoring the increased size of a file automatically by using Crontab to run it routinely.#If you need to monitor the result of it, you can add monitor to this log-file by using Watchdog.#Use log rotate to rotate this \"logSizeMonitor.log\"

time_now=`date \"+%Y-%m-%d %H:%M:%S\"`

time_bef=$(date --date=\"1 hour ago\" +\"%Y-%m-%d %H:%M:%S\")logfile=./logSizeMonitor.log

#the log the you need to monitor

hca_server_logs=\"/home/shirley/hca-server.log\"size=`ls -l $hca_server_logs`;size=${size#*'r '};size=${size%% *};lastN=`cat $logfile | tail -1`;if [ \"$lastN\" = \"\" ]; then lastN=0fi

add_h=$[($size-$lastN)/1048576];

size_h=$[$size/1048576];

note=\"From ${time_bef} to ${time_now}, log has increased: $add_h M, and the log size now is : $size_h M;\";echo $note >> $logfile

#If the log size has increased more than 100 M during the last one hour, then write log as KO!if [ $add_h -gt 100 ]; then echo \"KO\" >> $logfileelse

echo \"OK\" >> $logfilefi

echo $size >> $logfile &

使⽤说明:

这⼀脚本可⽤以监控单个⽂件在特定时间区间的增长情况,需要配合crontab使⽤。关于logRotate的⽅案,可根据实际情况⾃⾏调整。待开发:发现单个⽂件⼤⼩增长异常时,发送邮件告警!

logSizeMonitor.log

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igat.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务