diff --git a/tsshbatch.py b/tsshbatch.py index 38ecf7d..36d8a0c 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -1,14 +1,17 @@ #!/usr/bin/env python # Non-Interactive ssh Connection -# $Id: tsshbatch.py,v 1.102 2010/12/14 18:47:50 tundra Exp $ +# $Id: tsshbatch.py,v 1.103 2010/12/14 19:19:07 tundra Exp $ import paramiko import sys + ##### # Constants And Literals ##### +PADWIDTH = 35 +FAILURE = "Command Failed" SEPARATOR = " ---> " USAGE = "Usage: sshlogin.py username password hostname command" @@ -55,9 +58,21 @@ ssh = paramiko.SSHClient() -PrintStdout(host + SEPARATOR, TERMINATOR="") -ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) -ssh.connect(host, username=user, password=pw) -stdin, stdout, stderr = ssh.exec_command(cmd) -PrintStdout(stdout) +# Report attempt + +hostid = host + SEPARATOR +PrintStdout(hostid + (" " * (PADWIDTH - len(hostid))), TERMINATOR="") + +# Connect and run the command, reporting results as we go + +try: + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + ssh.connect(host, username=user, password=pw) + stdin, stdout, stderr = ssh.exec_command(cmd) + PrintStdout(stdout) + +except: + PrintStdout([FAILURE]) + +