我有两个具有不同IP的NTP服务器。
我正在尝试创建一个bash脚本,使系统时钟与"ntpdate“客户端同步。如果第一个NTP服务器没有响应,我的脚本应该尝试连接到第二个NTP服务器。
我尝试以这种方式创建一个名为RESULT的系统变量: RESULT = ntpdate 192.168.100.41
NTP同步是有效的,但是当我创建一个"echo $RESULT“时,它的值总是0。所以我的问题是:有没有正确的方法来做这件事?多么?
发布于 2012-02-17 18:38:44
只需检查存储在$?中的执行状态
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"https://stackoverflow.com/questions/9326336
复制相似问题