- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有两个具有不同 IP 的 NTP 服务器。
我正在尝试制作一个 bash 脚本,使系统时钟与“ntpdate”客户端同步。如果第一个 NTP 服务器没有响应,我的脚本应该尝试连接到第二个 NTP 服务器。
我试图以这种方式创建一个名为 RESULT 的系统变量:结果 = ntpdate 192.168.100.41
NTP 同步有效,但当我发出“echo $RESULT”时,它的值始终为 0。所以我的问题是:有没有正确的方法来做到这一点?怎么办?
最佳答案
只需检查存储在 $?
中的执行状态:
ntpdate foo.com
17 Feb 12:35:13 ntpdate[16218]: no server suitable for synchronization found
echo $?
1
ntpdate 1.europe.pool.ntp.org
17 Feb 12:36:26 ntpdate[16220]: step time server 109.230.243.8 offset 27.014301 sec
echo $?
0
或者,如果您使用的是 Debian,请使用 ntpdate-debian 并在 /etc/default/ntpdate 中指定服务器列表,例如:
NTPSERVERS="0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org"
关于linux - 获取脚本的 ntpdate 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9326336/
当没有事件的互联网连接时在 Linux 上运行 ntpdate 程序会在控制台中显示此消息: Exiting, name server cannot be used: Temporary failur
在 RHEL 中,ntpdate 始终会以一定的偏移量同步时间,即使在以每秒一次的频率触发命令数百次之后也是如此。 最佳答案 每次同步时您都会看到几毫秒的偏移。这个是正常的。请参阅http://www
我正在尝试使用 ntpdate 命令对 2 个 Centos VM 进行时间同步,但它不起作用。 当运行 ntpdate 命令(ntpdate reference.time.machine)时,它显示
我有两个具有不同 IP 的 NTP 服务器。 我正在尝试制作一个 bash 脚本,使系统时钟与“ntpdate”客户端同步。如果第一个 NTP 服务器没有响应,我的脚本应该尝试连接到第二个 NTP 服
命令简介 ntpddate 命令用于使用网络计时协议(NTP)设置日期和时间。还可以用于同步时间,此命令需要具备root管理员权限才可执行。 [root@centos7
我正在尝试编写一个代码来监听消息,并在每次收到消息时强制执行 ntp 同步(使用 ntpdate 命令)。 代码是用c++写的,在Ubuntu 14.04上,运行OK。但是系统命令每次都失败,因为它没
我使用的是 BeagleBone,由于它没有内置 RTC 和备用电池,因此每次重启都会丢失日期。我可以使用以下命令轻松设置日期: /usr/bin/ntpdate -b -s -u pool.ntp.
我有一个 Bash 脚本可以更新我的 mac 的时间,但是自从更新了 Mojave 之后就找不到命令了: ntpdate -u time.apple.com 返回: ntpdate: command
我是一名优秀的程序员,十分优秀!