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

ssh '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.

  • 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

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

| improve this answer | |
  • 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

The line that works is as below:

ssh '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.

| improve this answer | |

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 'reboot --force > /dev/null'

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.