shell 計算故障時間 配合web監控

#!/bin/bash

fail_time(){

starttime=`tail -n 1000 checkfail.log |grep "$url"|grep "第1次"|tail -n 3|head -n 1|awk '{printf$1;printf" ";printf$2}'`  #取網站掛掉的時間
endtime=`tail -n 1000 checkfail.log |grep "$url"|grep "已恢復監控"|tail -n 1|awk '{printf$1;printf" ";printf$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"

}

企業微信效果

image.png



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章