简体   繁体   English

如何在两个不同的UNIX服务器上完全同时运行两个命令?

[英]How can i run two commands exactly at same time on two different unix servers?

My requirement is that i have to reboot two servers at same time (exactly same timestamp) . 我的要求是我必须同时(完全相同的时间戳)重新启动两台服务器。 So my plan is to create two shell script that will ssh to the server and trigger the reboot. 所以我的计划是创建两个shell脚本,这些脚本将SSH到服务器并触发重新启动。 My doubt is 我的疑问是

  • How can i run same shell script on two server at same time. 如何在两个服务器上同时运行相同的Shell脚本。 (same timestamp) (相同的时间戳记)
  • Even if i run Script1 &; 即使我运行Script1&; Script2. SCRIPT2。 This will not ensure that reboot will be issued at same time, minor time difference will be there. 这将无法确保将在同一时间发出重新引导信息,但会存在微小的时差。

If you are doing it remotely, you could use a terminal emulator with broadcast input, so that what you type is sent to all sessions of the open terminal. 如果要远程执行操作,则可以使用带有广播输入的终端仿真器,以便将键入的内容发送到打开的终端的所有会话中。 On Linux tmux is one such emulator. 在Linux上, tmux是一种这样的模拟器。

The other easiest way is write a shell script which waits for the same timestamp on both machines and then both reboot. 另一种最简单的方法是编写一个shell脚本,该脚本在两台计算机上等待相同的时间戳,然后都重新启动。

  • First, make sure both machine's time are aligned (use the best implementation of http://en.wikipedia.org/wiki/Network_Time_Protocol and your system's related utilities). 首先,确保两台机器的时间一致(使用http://en.wikipedia.org/wiki/Network_Time_Protocol的最佳实现以及系统的相关实用程序)。
  • Then, 然后,

    • If you need this just one time: on each servers do a 如果您仅需要一次:在每台服务器上执行一次
      echo /path/to/your/script | at ....
      ( .... being when you want it. See man at ). ....在您需要时。 man atman at )。

    • If you need to do it several times: use crontab instead of at 如果需要多次执行:使用crontab而不是at
      (see man cron and man crontab ) (请参阅man cronman crontab

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM