diff --git a/tsshbatch.py b/tsshbatch.py index 8cd2b15..826fe24 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # Non-Interactive ssh Connection -# $Id: tsshbatch.py,v 1.105 2010/12/14 19:47:21 tundra Exp $ +# $Id: tsshbatch.py,v 1.106 2010/12/14 20:45:30 tundra Exp $ import paramiko import sys @@ -10,6 +10,7 @@ # Constants And Literals ##### +INDENTWIDTH = 8 PADWIDTH = 30 FAILURE = "Command Failed" SEPARATOR = " ---> " @@ -25,7 +26,7 @@ def PrintStdout(messages, TERMINATOR="\n"): for msg in messages: - sys.stdout.write(msg + TERMINATOR) + sys.stdout.write(INDENT + str(msg) + TERMINATOR) # End of 'PrintStdout()' @@ -61,7 +62,9 @@ # Report attempt -PrintStdout(host + (" " * (PADWIDTH - len(host))) + SEPARATOR, TERMINATOR="") +INDENT = "" +PrintStdout([host + SEPARATOR]) +INDENT += " " * INDENTWIDTH # Connect and run the command, reporting results as we go @@ -69,11 +72,10 @@ 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([""]) + PrintStdout([stdout], TERMINATOR="") -except: - PrintStdout([FAILURE]) +except Exception as problem: + PrintStdout([problem])