如何解决更新时间的脚本
所以,我有一个获取日期和时间的脚本,但采用标准字符串格式。现在,当我通过 date -s "Feb 11 2021 8:43:00" 设置日期时,外壳允许它。但是当我的脚本尝试插入相同的字符串时,它不起作用,而是抛出此错误:
#!/bin/bash
# Automatically Updates System Time According to the NIST Atomic Clock in a Linux Environment
nistTime=$(curl -I --insecure 'https://nist.time.gov/' | grep "Date")
echo $nistTime
dateString=$(echo $nistTime | cut -d' ' -f2-7)
dayString=$(echo $nistTime | cut -d' ' -f2-2)
dateValue=$(echo $nistTime | cut -d' ' -f3-3)
monthValue=$(echo $nistTime | cut -d' ' -f1-1)
yearValue=$(echo $nistTime | cut -d' ' -f5-5)
timeValue=$(echo $nistTime | cut -d' ' -f5-5)
timeZoneValue=$(echo $nistTime | cut -d' ' -f7-7)
#echo $dateString
case $monthValue in
"Jan")
monthValue="01"
;;
"Feb")
monthValue="02"
;;
"Mar")
monthValue="03"
;;
"Apr")
monthValue="04"
;;
"May")
monthValue="05"
;;
"Jun")
monthValue="06"
;;
"Jul")
monthValue="07"
;;
"Aug")
monthValue="08"
;;
"Sep")
monthValue="09"
;;
"Oct")
monthValue="10"
;;
"Nov")
monthValue="11"
;;
"Dec")
monthValue="12"
;;
*)
continue
esac;
sudo date --utc -s $monthValue.$dateValue.$yearValue
触发上述错误的原因:
Date: Thu,11 Feb 2021 22:04:03 GMT
./settime.sh: line 51: continue: only meaningful in a `for',`while',or `until' loop
date: the argument ‘9:39’ lacks a leading '+';
when using an option to specify date(s),any non-option
argument must be a format string beginning with '+'
Try 'date --help' for more information.
对于为什么会这样的一些见解将不胜感激,或者我可以通过任何方式从终端自动更新时间。谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。