def execute(self): self.customize(self.options) connection = None try: connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options) connection.setWorkingDirectory(connection.getFile(self.remotePath)) # upload the script and pass it to powershell targetFile = connection.getTempFile("uploaded-powershell-script", ".ps1") OverthereUtils.write(String(self.script).getBytes(), targetFile) targetFile.setExecutable(True) scriptCommand = CmdLine.build( "powershell", "-NoLogo", "-NonInteractive", "-InputFormat", "None", "-ExecutionPolicy", "Unrestricted", "-Command", targetFile.getPath(), ) return connection.execute(self.stdout, self.stderr, scriptCommand) except Exception, e: stacktrace = StringWriter() writer = PrintWriter(stacktrace, True) e.printStackTrace(writer) self.stderr.handleLine(stacktrace.toString()) return 1
def execute(self): connection = None try: connection = self.getConnection() # upload the script and pass it to python exeFile = connection.getTempFile('script', '.py') OverthereUtils.write(String(self.script).getBytes(), exeFile) exeFile.setExecutable(True) scriptCommand = CmdLine.build('/usr/bin/python', exeFile.getPath()) return connection.execute(self.stdout, self.stderr, scriptCommand) except AttributeError, e: self.logger.error(str(e))
def execute(self): self.customize(self.options) connection = None try: connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options) connection.setWorkingDirectory(connection.getFile(self.TestPath)) # upload the ResultName and pass it to csResultName.exe ResultNameCommand = CmdLine.build(WlrunExe, "-Run", "-TestPath", TestPath, "-ResultName", ResultName) return connection.execute(self.stdout, self.stderr, ResultNameCommand) except Exception, e: stacktrace = StringWriter() writer = PrintWriter(stacktrace, True) e.printStackTrace(writer) self.stderr.handleLine(stacktrace.toString()) return 1
def execute(self, cmd, check_success=True, suppress_streaming_output=False): """ Executes the command on the remote system and returns the result :param cmd: Command line as an Array of Strings or String. A String is split by space. :param check_success: checks the return code is 0. On failure the output is printed to stdout and a system exit is performed :param suppress_streaming_output: suppresses the output of the execution when the session is in streaming mode. :return: CommandResponse """ if isinstance(cmd, basestring): cmd = cmd.split() cmdline = CmdLine.build(cmd) capture_so_handler = CapturingOverthereExecutionOutputHandler.capturingHandler( ) capture_se_handler = CapturingOverthereExecutionOutputHandler.capturingHandler( ) if self._stream_command_output and not suppress_streaming_output: console_so_handler = PyLoggerExecutionOutputHandler.sysoutHandler( self.logger) console_se_handler = PyLoggerExecutionOutputHandler.syserrHandler( self.logger) so_handler = MultipleOverthereExecutionOutputHandler.multiHandler( [capture_so_handler, console_so_handler]) se_handler = MultipleOverthereExecutionOutputHandler.multiHandler( [capture_se_handler, console_se_handler]) else: so_handler = capture_so_handler se_handler = capture_se_handler rc = self.get_conn().execute(so_handler, se_handler, cmdline) #wait for output to drain time.sleep(1) response = CommandResponse(rc=rc, stdout=capture_so_handler.outputLines, stderr=capture_se_handler.outputLines) if response.rc != 0 and check_success: if not self._stream_command_output and suppress_streaming_output: self.logger.error(StringUtils.concat(response.stdout)) self.logger.error(StringUtils.concat(response.stderr)) sys.exit(response.rc) return response
def execute(self): self.customize(self.options) connection = None try: connection = Overthere.getConnection(SshConnectionBuilder.CONNECTION_TYPE, self.options) # upload the script and pass it to python exeFile = connection.getTempFile('f5_disable', '.py') OverthereUtils.write(String(self.script).getBytes(), targetFile) exeFile.setExecutable(True) # run cscript in batch mode scriptCommand = CmdLine.build( '/usr/bin/python', exeFile.getPath() ) return connection.execute(self.stdout, self.stderr, scriptCommand) except Exception, e: stacktrace = StringWriter() writer = PrintWriter(stacktrace, True) e.printStackTrace(writer) self.stderr.handleLine(stacktrace.toString()) return 1
def execute(self): self.customize(self.options) connection = None try: connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options) connection.setWorkingDirectory(connection.getFile(self.remotePath)) # upload the script and pass it to cscript.exe targetFile = connection.getTempFile('uploaded-script', '.vbs') OverthereUtils.write(String(self.script).getBytes(), targetFile) targetFile.setExecutable(True) # run cscript in batch mode scriptCommand = CmdLine.build(cscriptExecutable, '//B', '//nologo', targetFile.getPath()) return connection.execute(self.stdout, self.stderr, scriptCommand) except Exception, e: stacktrace = StringWriter() writer = PrintWriter(stacktrace, True) e.printStackTrace(writer) self.stderr.handleLine(stacktrace.toString()) return 1
def execute(self): self.customize(self.options) connection = None try: connection = Overthere.getConnection( CifsConnectionBuilder.CIFS_PROTOCOL, self.options) connection.setWorkingDirectory(connection.getFile(self.remotePath)) # upload the script and pass it to cscript.exe targetFile = connection.getTempFile('uploaded-script', '.vbs') OverthereUtils.write(String(self.script).getBytes(), targetFile) targetFile.setExecutable(True) # run cscript in batch mode scriptCommand = CmdLine.build(cscriptExecutable, '//B', '//nologo', targetFile.getPath()) return connection.execute(self.stdout, self.stderr, scriptCommand) except Exception, e: stacktrace = StringWriter() writer = PrintWriter(stacktrace, True) e.printStackTrace(writer) self.stderr.handleLine(stacktrace.toString()) return 1
def local_execute(session, cmd): """ Executes the command on the remote system and returns the result :param session: checks the return code is 0. On failure the output is printed to stdout and a system exit is performed :param cmd: Command line as an Array of Strings or String. A String is split by space. :return: CommandResponse """ if isinstance(cmd, basestring): cmd = cmd.split() cmdline = CmdLine.build(cmd) capture_so_handler = CapturingOverthereExecutionOutputHandler.capturingHandler( ) capture_se_handler = CapturingOverthereExecutionOutputHandler.capturingHandler( ) console_so_handler = PyLoggerExecutionOutputHandler.sysoutHandler( session.logger) console_se_handler = PyLoggerExecutionOutputHandler.syserrHandler( session.logger) so_handler = MultipleOverthereExecutionOutputHandler.multiHandler( [capture_so_handler, console_so_handler]) se_handler = MultipleOverthereExecutionOutputHandler.multiHandler( [capture_se_handler, console_se_handler]) rc = session.get_conn().execute(so_handler, se_handler, cmdline) # wait for output to drain time.sleep(1) response = CommandResponse(rc=rc, stdout=capture_so_handler.outputLines, stderr=capture_se_handler.outputLines) if response.rc != 0: session.logger.error(StringUtils.concat(response.stdout)) session.logger.error(StringUtils.concat(response.stderr)) session.logger.error("Exit code {0}".format(response.rc)) sys.exit(response.rc) return response
def execute(self): self.customize(self.options) connection = None try: connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options) connection.setWorkingDirectory(connection.getFile(self.remotePath)) # upload the script and pass it to cscript.exe targetFile = connection.getTempFile('parameters', '.txt') OverthereUtils.write(String(self.script).getBytes(), targetFile) targetFile.setExecutable(True) exeFile = connection.getTempFile('HpToolsLauncher', '.exe') sysloader = ClassLoader.getSystemClassLoader() OverthereUtils.write(sysloader.getResourceAsStream("HpTools/HpToolsLauncher.exe"), exeFile) exeFile.setExecutable(True) # run cscript in batch mode scriptCommand = CmdLine.build(exeFile.getPath(), '-paramfile', targetFile.getPath()) return connection.execute(self.stdout, self.stderr, scriptCommand) except Exception, e: stacktrace = StringWriter() writer = PrintWriter(stacktrace, True) e.printStackTrace(writer) self.stderr.handleLine(stacktrace.toString()) return 1
%s %s """ % (cmdLogon, cmdProject) #print script print "-------------------------" stdout = CapturingOverthereExecutionOutputHandler.capturingHandler() stderr = CapturingOverthereExecutionOutputHandler.capturingHandler() try: connection = LocalConnection.getLocalConnection() targetScript = connection.getTempFile('oc-script', '.bat') OverthereUtils.write( String(script).getBytes(), targetScript) targetScript.setExecutable(True) cmd = CmdLine.build( targetScript.getPath() ) connection.execute( stdout, stderr, cmd ) except Exception, e: stacktrace = StringWriter() writer = PrintWriter( stacktrace, True ) e.printStackTrace(writer) stderr.hadleLine(stacktrace.toString()) # set variables output = stdout.getOutput() error = stderr.getOutput() if len(output) > 0: print "```" print output