diff --git a/tsshbatch.py b/tsshbatch.py index 826fe24..0e39155 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -1,8 +1,9 @@ #!/usr/bin/env python # Non-Interactive ssh Connection -# $Id: tsshbatch.py,v 1.106 2010/12/14 20:45:30 tundra Exp $ +# $Id: tsshbatch.py,v 1.107 2010/12/15 16:30:32 tundra Exp $ import paramiko +import socket import sys @@ -18,6 +19,13 @@ ##### +# Error Messages +##### + +eNOCONNECT = "Cannot Connect! (Name/Address Bad? Destination Unreachable?)" +eNOLOGIN = "Cannot Login! (Login/Password Bad?)" + +##### # Print Message(s) To stdout ##### @@ -26,7 +34,7 @@ def PrintStdout(messages, TERMINATOR="\n"): for msg in messages: - sys.stdout.write(INDENT + str(msg) + TERMINATOR) + sys.stdout.write(INDENT + msg + TERMINATOR) # End of 'PrintStdout()' @@ -56,6 +64,22 @@ # Otherwise let the user know else: + + + + + + + + + + + + + + + + ErrorExit(USAGE) ssh = paramiko.SSHClient() @@ -72,10 +96,14 @@ ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(host, username=user, password=pw) stdin, stdout, stderr = ssh.exec_command(cmd) - PrintStdout([stdout], TERMINATOR="") + PrintStdout(stdout.readlines()) -except Exception as problem: - PrintStdout([problem]) +except paramiko.AuthenticationException: + PrintStdout([eNOLOGIN]) +except socket.gaierror: + PrintStdout([eNOCONNECT]) - +except socket.error: + PrintStdout([eNOCONNECT]) +