简体   繁体   中英

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. My doubt is

  • How can i run same shell script on two server at same time. (same timestamp)
  • Even if i run Script1 &; 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.

The other easiest way is write a shell script which waits for the same timestamp on both machines and then both reboot.

  • 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).
  • 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 ).

    • If you need to do it several times: use crontab instead of at
      (see man cron and man crontab )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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