我需要使用以下URL运行curl,并将当前系统时间与输出中显示的时间进行比较。如果当前时间比输出时间大5分钟,那么我需要一封电子邮件提醒。
# curl -g http://new.abc.com/arcfilesync/cachejob?jobType=CACHEBUILD
null('{"status":"RUNNING","lastRunTime":"Mon Jun 13 2016 08:58:13 AM","lastRunStatus":"SUCCESS"}')
有人可以指导我写这个吗?
答案 0 :(得分:0)
试试这个脚本:
#!/bin/bash
time1="Mon Jun 13 2016 08:58:13 AM";
timestamp1=$(date --date="$time1" +%s)
# create current date
time2=`date +%Y-%m-%d\ %H:%M:%S`
# Compute the timestamp
timestamp2=`date --date="$time2" +%s`
# get the difference between dates in seconds
let "diff=$timestamp2-$timestamp1"
# Compute the diff in minutes
let "diffInMin=$diff/60"
echo "diff $time1 <--> $time2"
echo "$diffInMin"
将在几分钟内输出差异:
./getTimeDiff.sh
diff Mon Jun 13 2016 08:58:13 AM <--> 2016-06-13 11:13:36
135
如果将从字符串中的时间创建时间戳并将其与当前时间进行比较。现在,您只需解析curl
请求并从那里获取时间。我会使用awk