如何获得两台 ubuntu 机器之间的时差

how to get the time difference between two ubuntu machines

我需要获得两台 Ubuntu Linux 机器之间的时差,配置尽可能少。请注意,这不是系统时钟的网络 latency.difference 毫秒或秒.详细步骤将不胜感激。

假设您知道如何设置 ssh 身份验证,这样您就不需要输入用户的密码,下面的 shell 命令将为您提供以秒为单位的时差。如果你想要更高的精度,你可以使用日期格式化字符串来获得纳秒级的时间。

echo $(($(ssh machine1 date +%s) - $(ssh machine2 date +%s)))

当然执行这两个ssh命令是有时间差的。所以得到的时间不是很准确。这可能适合您,也可能不适合您。

如果你想要更准确的东西,你可以使用 ntp 如果它已经在你的服务器上设置或者你可以设置它:https://superuser.com/questions/408753/determine-the-time-difference-between-two-linux-servers