#!/bin/bash
fail_time(){
starttime=`tail -n 1000 checkfail.log |grep "$url"|grep "第1次"|tail -n 3|head -n 1|awk '{print $1, $2}'` #取网站挂掉的时间
endtime=`tail -n 1000 checkfail.log |grep "$url"|grep "已恢复监控"|tail -n 1|awk '{print $1, $2}'` #取网站恢复的时间
startm=$(date --date="$starttime" +%M);
endm=$(date --date="$endtime" +%M);
starth=$(date --date="$starttime" +%H);
endh=$(date --date="$endtime" +%H);
startd=$(date --date="$starttime" +%d);
endd=$(date --date="$endtime" +%d);
echo "本次故障开始时间 $starttime"
echo "本次故障结束时间 $endtime"
day=$(($((10#$endd)) - $((10#$startd))))
hour=$(($((10#$endh)) - $((10#$starth))))
minute=$(($((10#$endm)) - $((10#$startm))))
total=$(($(($day * 24 * 60)) + $(($hour * 60 )) + $minute))
echo "本次故障持续时间: $((total / 60)) h $(($total % 60)) m"
}企业微信效果

本文介绍了一段bash脚本,用于从日志文件中提取特定URL的故障开始和结束时间,通过解析这些时间,计算并输出故障的持续时间,包括小时和分钟。
2009

被折叠的 条评论
为什么被折叠?



