Tim Hatch

Weblog | Photos | Projects | Panoramas | About

OpenSSH return codes 18 Feb, 2010

I’ve used openssh for many years, and dropbear for about two. Today I ran into a problem that was intermittently failing. I have an upgrade script that essentially boils down to:

ssh device do_stuff
ssh webservice change_something
ssh device udpate_config

At the top of my script, I want to make sure that an ssh agent is set up and the device has my public key, so I also include:

ssh -o 'batchmode yes' device 'exit 0'

With the versions I’m using (OpenSSH_5.2p1 to a dropbear v0.50 server), this is fundamentally broken, returning 255 most of the time and 0 every now and then. A workaround, in case you hit this too:

ssh -o 'batchmode yes' device 'echo Works' | grep -q Works

This preserves the $? being 0 for success, and nonzero otherwise.