#!/bin/bash
ctime=日期+%s
# returns 1618634997 to $ctime
stime=$(wget --server-response --spider http://www.server.org/news_32.mp3 2>&1 | grep -i Last-Modified)
# returns : Last-Modified: Sat, 17 Apr 2021 04:49:57 GMT # into the variable $stime
我需要将$stime转换为划时代的时间,将其放在$etime中进行比较,然后决定是否下载文件。
需要一些代码来操作字符串。
进行日期比较
diff=$(( (ctime - eftime) / 86400 ))
echo $diff以天为单位返回差。
我的解决方案,经过多次尝试找到原来的字符串。
stime=$(wget --server-response --spider http://server.org.au/local.mp3 2>&1 | grep -i Last-Modified)
a=$stime
a=${a/*,/} ; a=${a/\ GMT/} ; dmt=${a/2021 /} ; dm=${a/2021*/} ; tm=${dmt/????????/} ; dd=${dm%?????*} ; mmm=${dm#*????}
fst="${mmm}${dd} ${tm}"
epoch=$(date -d "${fst}" +"%s")
echo "server file time = $fst"
ftime=$epoch
ctime=date +%s
diff=$(( (ctime - ftime) / 86400 ))
echo "age "$diff" days"
exit
非常尴尬,我知道:)谢谢你的答案,这个网站很新,现在试试简单的方法。
发布于 2021-04-21 09:57:29
尝试以下几点:
eftime=$(date -d "$(wget --server-response --spider http://www.server.org/news_32.mp3 2>&1 | awk -F: '/Last-Modified/ { print $2 }')" +%s)
diff=$(( (ctime - eftime) / 86400 ))
echo $diff解释:
wget --server-response --spider http://www.server.org/news_32.mp3 2>&1 | awk -F: '/Last-Modified/ { print $2 }'获取wget的输出,然后使用“最后修改”搜索一行,然后打印第二个":“分隔字段。将其用作日期描述符,并使用+%s以划时代格式打印。
发布于 2021-04-21 11:04:38
你可以同时使用日期。
得到划时代的秒并把它转换回正常的日期.
date --date="@$(date +%s)"如果你喜欢Lua那你可以..。
-- get epoch seconds
>os.time()
1619002966
-- Convert it to a date
>os.date(_,os.time())
Wed Apr 21 13:03:11 2021https://stackoverflow.com/questions/67188593
复制相似问题