def runScriptOutput(host, cmd): try: checkItem = 'Run script Output' #prefix bgcolor stdin, stdout, stderr = execSudoCommand(host, cmd) lines = [] lines = stdout.read().split() if (init.bColorTag): msg = "RUN> " + cmd + "\n" #prefix msg else: msg = "" skipPwd = 0 for index, value in enumerate(lines): if (host[2] == "root"): skipPwd = -1 elif "password" in value: skipPwd = index + 2 #print "%d %s :%d" % (index, value,skipPwd) if (skipPwd != 0) and (index > skipPwd): if ("201" in value) or (":" in value) or (value.isdigit()): msg = msg + "\n" + value else: msg += " " + value logStatus(checkItem, host[4], msg) except Exception as e: logStatus(checkItem, host[4], "Error" + str(e)) raise ConnectionError('Connection error')
def runScriptOutput(host, cmd): try: stdin, stdout, stderr = execSudoCommand(host, cmd) lines = [] lines = stdout.read().split() msg =">" skipPwd = 0 #usually index > 4, value @ 5 for index, value in enumerate(lines): msg += value+" " print "%-15s) %s" %(host[4],msg) except Exception as e: print host[4]+ str(e)
def getOneOutput(host, cmd): try: stdin, stdout, stderr = execSudoCommand(host, cmd) lines = [] lines = stdout.read().split() msg = "" skipPwd = 0 for index, value in enumerate(lines): if (host[2] == "root"): skipPwd = -1 elif "password" in value: skipPwd = index + 2 if (skipPwd != 0) and (index > skipPwd): msg = value return msg except Exception as e: print str(e)
def runScriptOutput(host, cmd): try: stdin, stdout, stderr = execSudoCommand(host, cmd) lines = [] lines = stdout.read().split() msg = "" skipPwd = 0 for index, value in enumerate(lines): if (host[2] == "root"): skipPwd = -1 elif "password" in value: skipPwd = index + 2 #print "%d %s :%d" % (index, value,skipPwd) if (skipPwd != 0) and (index > skipPwd): msg = value return msg except Exception as e: #print str(e) raise ConnectionError('Connection error')
def checkValue(host, req, path): try: checkItem = 'Check Value' cmd = "sed -n '/" + req + "/p' " + path stdin, stdout, stderr = execSudoCommand(host, cmd) lines = [] lines = stdout.read().split() msg = "RUN> " + cmd + "\n" skipPwd = 0 for index, value in enumerate(lines): if (host[2] == "root"): skipPwd = -1 elif "password" in value: skipPwd = index + 2 #print "%d %s :%d" % (index, value,skipPwd) if (skipPwd != 0) and (index > skipPwd): msg += " " + value logStatus(checkItem, host[4], msg) except Exception as e: logStatus(checkItem, host[4], "Error" + str(e)) raise ConnectionError('Connection error throw')
def runScriptOutput(host, cmd): try: stdin, stdout, stderr = execSudoCommand(host, cmd) lines = [] lines = stdout.read().split() msg = "" skipPwd = 0 #usually index > 4, value @ 5 for index, value in enumerate(lines): if (host[2] == "root"): skipPwd = -1 elif "password" in value: skipPwd = index + 2 #print "%d %s :%d" % (index, value,skipPwd) if (skipPwd != 0) and (index > skipPwd): msg += value + " " if (len(msg) > 20): return "Streaming" else: return "Not Streaming" except Exception as e: #print str(e) raise ConnectionError('Connection error')
def runScriptPrint(host, cmd, param): try: checkItem = 'Run script Print' stdin, stdout, stderr = execSudoCommand(host, cmd) lines = [] lines = stdout.read().split() msg = "RUN> " + cmd + "\n" skipPwd = 0 for index, value in enumerate(lines): if (host[2] == "root"): skipPwd = -1 elif "password" in value: skipPwd = index + 2 #print "%d %s :%d" % (index, value,skipPwd) if (skipPwd != 0) and (index > skipPwd): if (param in value): msg = msg + "\n" + value else: msg += " " + value logStatus(checkItem, host[4], msg) except Exception as e: logStatus(checkItem, host[4], "Error" + str(e)) raise ConnectionError('Connection error throw')
def sqlCmd(host, cmd): print bcolors.HIGHBLUE + host[4] + ": " + cmd + bcolors.RESET try: msg1 = "" skipPwd = 0 #usually index > 4, value @ 5 stdin, stdout, stderr = execSudoCommand(host, cmd) lines = [] lines = stdout.read().split() for index, value in enumerate(lines): if (host[2] == "root"): skipPwd = -1 elif "password" in value: skipPwd = index + 2 #print "%d %s :%d" % (index, value,skipPwd) if (skipPwd != 0) and (index > skipPwd): value = value.replace("-", "") if (value.find("|") != -1): msg1 += "\n" + value else: msg1 += " " + value print msg1 except Exception as e: print str(e)