From: Eric S. Raymond Date: Wed, 13 Oct 2010 09:52:09 +0000 (-0400) Subject: Handle some error conditions more gracefilly. X-Git-Tag: 1.5~1 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=6e0e45c48be25f8d2e5955de53a40cb4ac024303;p=ssh-installkeys.git Handle some error conditions more gracefilly. Patch thanks to Dhirendra Singh Kholia --- diff --git a/ssh-installkeys b/ssh-installkeys index 03ef114..f809fb9 100755 --- a/ssh-installkeys +++ b/ssh-installkeys @@ -580,7 +580,7 @@ class ssh_session: if self.verbose: sys.stderr.write("-> " + command + "\n") while True: - seen=child.expect([EOF,'assword:','continue connecting (yes/no)?']) + seen=child.expect([EOF,'assword:','continue connecting (yes/no)?','Permission denied','refused','not resolve']) if self.verbose: sys.stderr.write("<- " + child.before + "\n") if seen == 0: @@ -595,6 +595,16 @@ class ssh_session: if self.verbose: sys.stderr.write("Saw 'continue connecting' prompt...\n") child.sendline("yes") + elif seen == 3: + sys.stderr.write("FAILURE: check your password\n") + raise RuntimeError + elif seen == 4: + sys.stderr.write("FAILURE: cannot connect to port " + self.port + "\n") + raise RuntimeError + elif seen == 5: + sys.stderr.write("FAILURE: check hostname\n") + raise RuntimeError + return child.before def ssh(self, command): return self.__exec("ssh -p %s -l %s %s \"%s\""%(session.port, self.user,self.host,command)) @@ -749,6 +759,8 @@ if __name__ == '__main__': session.scp(keyfile, "~/.ssh/authorized_keys") except SystemExit: pass + except RuntimeError: + sys.exit(-1) # It's all over now... os.remove(keyfile) if check: