![pssh + 验证机器之间的日期,如果日期差异超过 3 秒则发出警报](https://linux22.com/image/157077/pssh%20%2B%20%E9%AA%8C%E8%AF%81%E6%9C%BA%E5%99%A8%E4%B9%8B%E9%97%B4%E7%9A%84%E6%97%A5%E6%9C%9F%EF%BC%8C%E5%A6%82%E6%9E%9C%E6%97%A5%E6%9C%9F%E5%B7%AE%E5%BC%82%E8%B6%85%E8%BF%87%203%20%E7%A7%92%E5%88%99%E5%8F%91%E5%87%BA%E8%AD%A6%E6%8A%A5.png)
我们使用下面的 pssh 命令来查看机器之间的时间差异是否超过 3 秒
pssh -i -o /tmp/out/ -e /tmp/err/ -H "master01 master02 master03 worker01 worker02" -l root -x '-q -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PreferredAuthentications=publickey -o PubkeyAuthentication=yes' date
[1] 12:15:43 [SUCCESS] worker02
Fri Jul 12 12:15:43 UTC 2019
[2] 12:15:43 [SUCCESS] master03
Fri Jul 12 12:15:43 UTC 2019
[3] 12:15:43 [SUCCESS] worker01
Fri Jul 12 12:15:43 UTC 2019
[4] 12:15:43 [SUCCESS] master01
Fri Jul 12 12:15:43 UTC 2019
[5] 12:15:43 [SUCCESS] master02
Fri Jul 12 12:15:43 UTC 2019
现在我们要在 bash 脚本中设置 pssh
我们想检查一下时间是否超过了3秒机器之间
如何使用 awk/perl oneliner /bash/ ,以验证时间不超过 3 秒?
或者为了仅显示日期结果:
pssh -i -H "master01 master02 master03 worker01 worker02" 2>/dev/null -l root -x '-q -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PreferredAuthentications=publickey -o PubkeyAuthentication=yes' date | grep -v "^\["
Fri Jul 12 12:37:35 UTC 2019
Fri Jul 12 12:37:35 UTC 2019
Fri Jul 12 12:37:35 UTC 2019
Fri Jul 12 12:37:35 UTC 2019
Fri Jul 12 12:37:35 UTC 2019
注意 - 我们的集群中有超过 452 台 redhat 7.2 机器(以下是示例)