diff --git a/tsshbatch.py b/tsshbatch.py index dca4f96..5283066 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.222 2016/01/16 20:04:48 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.223 2016/01/17 02:03:28 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" PROGDATE = "2011-2016" @@ -202,20 +202,21 @@ # Options That Can Be Overriden By User #### -ABORTBADSUDO = True # Abort after a sudo promotion error -ABORTONFXERROR = True # Abort after a file transfer error -BANNERSON = False # Print start/stop banner info -GETSUDOPW = False # Prompt for sudo password -Hosts = [] # List of hosts to target -KEYEXCHANGE = False # Do key exchange-based auth? -LOGFILE = "/dev/null" # Where paramiko logging output goes -PROMPTUSERNAME = False # Don't use $USER, prompt for username -PWORD = "" # Password -REDIRSTDERR = False # Redirect stderr to stdout -REPORTERR = True # Report stderr output from remote host -TESTMODE = True # Run program in test mode, don't actually execute commands -TIMEOUT = 15 # Connection attempt timeout (sec) -UNAME = "" # Login name +ABORTBADSUDO = True # Abort after a sudo promotion error +ABORTONFXERROR = True # Abort after a file transfer error +BANNERSON = False # Print start/stop banner info +GETSUDOPW = False # Prompt for sudo password +Hosts = [] # List of hosts to target +KEYEXCHANGE = False # Do key exchange-based auth? +LOGFILE = "/dev/null" # Where paramiko logging output goes +PROMPTUSERNAME = False # Don't use $USER, prompt for username +PWORD = "" # Password +REDIRSTDERR = False # Redirect stderr to stdout +REPORTERR = True # Report stderr output from remote host +SSHCONFIGFILE = "~/.ssh/config" # Default ssh configuration file location +TESTMODE = True # Run program in test mode, don't actually execute commands +TIMEOUT = 15 # Connection attempt timeout (sec) +UNAME = "" # Login name # Noise levels @@ -234,6 +235,7 @@ FileIncludeStack = [] Get_Transfer_List = collections.OrderedDict() Put_Transfer_List = collections.OrderedDict() +SSH_Configuration = {} ##### @@ -349,7 +351,7 @@ # Get an sftp connection and move files try: - ssh = SSHConnect(host, user, pw, TIMEOUT) + ssh = SSH_Connect(host, user, pw, TIMEOUT) sftp = ssh.open_sftp() for src in filelist: @@ -430,7 +432,7 @@ # Connect and run the command, reporting results as we go try: - ssh = SSHConnect(host, user, pw, TIMEOUT) + ssh = SSH_Connect(host, user, pw, TIMEOUT) if NOISELEVEL != QUIET: PrintReport([host, CONSUCCESS], FORMAT=Format) @@ -677,10 +679,10 @@ ##### -# Setup An SSH Connection +# Setup An ssh Connection ##### -def SSHConnect(host, user, pw, time): +def SSH_Connect(host, user, pw, time): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) @@ -692,7 +694,31 @@ return ssh -# End of 'SSHConnect()' +# End of 'SSH_Connect()' + + +##### +# Read Any Local SSH Configuration +##### + +def SSH_GetConfig(filename): + + with open(os.path.expanduser(filename)) as f: + + cfg = paramiko.SSHConfig() + cfg.parse(f) + ret_dict = {} + + for d in cfg._config: + _copy = dict(d) + del _copy['host'] + for host in d['host']: + ret_dict[host] = _copy['config'] + + return ret_dict + + +# End of 'SSH_GetConfig()' ##### @@ -1045,6 +1071,10 @@ else : + # Get the local SSH configuration + + SSH_Config = SSH_GetConfig(SSHCONFIGFILE) + # Check to see if user is trying to override any builtins protected = [] @@ -1109,4 +1139,3 @@ PrintStdout(BANNERMSG % (BANNEREND, time.strftime("%Y-%m-%d"), time.strftime("%H:%M:%S"))) PrintStdout(BANNERTIME % float(time.time() - starttime)) -