微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更新时间的脚本

如何解决更新时间的脚本

所以,我有一个获取日期和时间的脚本,但采用标准字符串格式。现在,当我通过 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?