![](/img/trans.png)
[英]Writing a bash script that compares two log files comparing timestamps
[英]Bash comparing two timestamps
我想比較“endts(它包含時間戳)”是否早於 24 小時但我堅持使用它。
endline=`cat /xy.json 2>&1 | grep -ie endTime`
endts=`sed s/\"endTime\":\ //g <(echo $endline) | sed s/,//`
current=`date +%s`
if [ $endts -gt $current ]; then
msg='older than 24hrs'
exitcd=2
else
msg='not older than 24hrs'
exitcd=0
fi
echo $msg
exit $exitcd
我試過 -gt 86400 但它不起作用
24 小時是 86400 秒。 因此,為了比較日期(秒)是否超過 24 小時,您必須將其與date +%s - 86400
進行比較
並且比較應該是-lt
... if [ $endts -lt $(($(date +%s) - 86400 )) ] ; 然后 ...
如果超過 24 小時前生成了真正的$endts
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.