0

I'm trying to reboot one box from another, using the following command:

ssh 10.0.0.26 'reboot --force'

I expect this to block for a short while until the other box reboots, then return. What I see happening is no activity for a while, then if I press a key, I get "Write failed: Broken pipe".

The reboot of the other box works just as expected, but I'd like to clear up the output on the local box, ideally without just hiding it all in /dev/null.

I'm using OpenSSH 5.3p1 on Redhat 6.

Edit: I've foundmy own solution; I'll add this as an answer below. Seems I can't accept this just yet, though. I guess this is to give others a chance to come in with a better solution.

me_and
  • 158
  • 1
  • 9
  • A review of `man reboot` would suggest that using the force option precludes a normal shutdown for sshd - i.e. you're killing sshd and your client is (legitimately) notifying you. Hiding with redirection to /dev/null is the only way around the warning if you have to use the force option on the remote server. – danlefree Nov 30 '10 at 15:41

3 Answers3

1

You can schedule reboot instead of just rebooting immediately. Have a look at this post.

Khaled
  • 36,533
  • 8
  • 72
  • 99
  • Scheduling reboot using `shutdown` gives very different behaviour to `reboot --force`. The latter reboots the system _immediately_, the former performs a nice friendly shutdown – me_and Nov 30 '10 at 12:19
  • 1
    @me_and: You can use "at" to schedule the system reboot using "reboot --force" or any other command. – Khaled Nov 30 '10 at 12:29
1

The line that works is as below:

ssh 10.0.0.26 'reboot --force >/dev/null &'

The final & tells the other system to run the command in the background. This alone isn't enough, however, as the ssh connection tries to stay open in case of any output. Hence sending stdout to null.

me_and
  • 158
  • 1
  • 9
0

If you really do want to wait until the reboot is in full swing (e.g. ssh sessions killed), then poll the server once per second and quit if it failed to answer within 5 tries:

ssh -o ServerAliveInterval=1 -o ServerAliveCountMax=5 10.0.0.26 'reboot --force > /dev/null'

[A discussion here pointed me to the right parameters.]

zerolagtime
  • 1,428
  • 9
  • 10