diff --git a/tsshbatch.py b/tsshbatch.py index 22b782e..950967f 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.196 2014/12/03 19:54:51 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.197 2014/12/04 01:01:26 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" PROGDATE = "2011-2014" @@ -46,6 +46,7 @@ # Imports ##### +import commands import getopt import getpass import os @@ -65,6 +66,7 @@ COMMENT = '#' COMMANDS = 'Commands' CONSUCCESS = 'SUCCESS: Connection Established' +EXECUTE = '!' GETFILES = 'Files To GET' HOSTSEP = '-' HOSTNOISE = '[%s]' @@ -124,7 +126,7 @@ ##### -# Builtin Symbols +# Builtin Definitions ##### DATE = '__DATE__' @@ -134,12 +136,14 @@ HOSTSHORT = '__HOSTSHORT__' TIME = '__TIME__' + # This is needed to differentiate between user-defined and builtin # variables later in order to support the user being able to redefine # them. BuiltIns = (DATE, DATETIME, HOSTNAME, HOSTNUM, HOSTSHORT, TIME) + ##### # Global Symbol Table ##### @@ -152,6 +156,7 @@ ##### eBADARG = "Invalid command line: %s!" +eBADEXEC = "Execution variable failed: %s" eBADFILE = "Cannot open '%s'!" eBADSUDO = "sudo Failed (Check Password Or Command!) sudo Error Report: %s" eBADTXRQ = "Bad Transfer Request: %s Must Have Exactly 1 Source And 1 Destination!" @@ -551,6 +556,25 @@ name = line.split(ASSIGN)[0].strip() val = "=".join(line.split(ASSIGN)[1:]).strip() + # Process references to execution variables + + if val.startswith(EXECUTE): + + try: + + origval = val + status, val = commands.getstatusoutput(val[1:].strip()) + + # Blow out if the command failed + + if status: + raise + + except: + + PrintReport([PROGNAME, eBADEXEC % origval], HANDLER=PrintStderr) + ErrorExit("") + if name: SymbolTable[name] = val