嵌入式poky,没有ntpdate可用。
以下任何命令似乎都不合适:
# date -s "$(curl -s --head http://google.com | grep '^Date:' | cut -d' ' -f 3-)"
date: invalid date '08 Mar 2021 13:22:34 GMT'# date -s "$(curl -s --head http://google.com | grep '^Date:' | cut -d' ' -f 3-6)"
date: invalid date '08 Mar 2021 13:22:34'#date +"%d %b %Y %H:%M:%S" -s "$(curl -s --head http://google.com | grep '^Date:' | cut -d' ' -f 3-6)"
date: invalid date '08 Mar 2021 13:22:34'BusyBox日期只接受下列日期格式:
@seconds_since_1970
hh:mm[:ss]
[YYYY.]MM.DD-hh:mm[:ss]
YYYY-MM-DD hh:mm[:ss]
[[[[[YY]YY]MM]DD]hh]mm[.ss]如果-D选项在您使用的BusyBox版本中可用,您可以按照斯蒂尔·德里弗的建议使用以下命令:
busybox date -d '08 Mar 2021 13:22:34' -D '%d %b %Y %H:%M:%S'发布于 2021-03-09 15:36:19
最后,我解析了来自谷歌的时间字符串,将其转换为busybox date友好格式(YYYY-mm-dd HH:MM:SS)。希望将来有人会发现这是有用的。
#!/bin/sh
monthnumber() {
month=$1
months="JanFebMarAprMayJunJulAugSepOctNovDec"
tmp=${months%%$month*}
month=${#tmp}
monthnumber=$((month/3+1))
printf "%02d\n" $monthnumber
}
G_DATE="$(curl -s --head http://google.com | grep '^Date:' | cut -d' ' -f 3-6)"
G_SPLIT=($(echo $G_DATE | tr " "))
BB_DATE="${G_SPLIT[2]}-$(monthnumber ${G_SPLIT[1]})-${G_SPLIT[0]} ${G_SPLIT[3]}"
date -s "$BB_DATE"monthnumber()函数取自https://stackoverflow.com/a/41385862/9815377
发布于 2021-03-08 14:22:47
也许你可以更新一下百事箱。我得到了1.30版本的命令
https://unix.stackexchange.com/questions/638181
复制相似问题