您的位置:首页 > 运维架构 > Shell

Shell 计算故障时间

2019-10-19 22:02 1496 查看
#!/bin/bash
## 配合web监控https://blog.51cto.com/junhai/2437965

fail_time(){

starttime=`tail -n 500 checkfail.log |grep "$url"|grep "第1次"|tail -n 3|head -n 1|awk '{print $1, $2}'`
endtime=`tail -n 500 checkfail.log |grep "$url"|grep "已恢复监控"|tail -n 1|awk '{print $1, $2}'`
oldtime=`tail -n 500 checkfail.log |grep "$url"|grep "已恢复监控"|tail -n 2|head -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 "上次故障恢复时间 $oldtime"
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"

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: