def getGrepValue(self, para="", value="", path=""): """ function : grep value input : string,value,path output: status, output """ if not os.path.exists(path): raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % path) cmd = g_Platform.getGrepCmd() + " %s '%s' '%s'" % (para, value, path) (status, output) = subprocess.getstatusoutput(cmd) if status != 0: raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd + " Error:\n%s" % output) return status, output
def executePingCmd(self, ipAddress): """ function : Send the network command of ping. input : String output : NA """ pingCmd = g_Platform.getPingCmd(ipAddress, "5", "1") cmd = "%s | %s ttl | %s -l" % (pingCmd, g_Platform.getGrepCmd(), g_Platform.getWcCmd()) (status, output) = subprocess.getstatusoutput(cmd) if (str(output) == '0' or status != 0): g_lock.acquire() g_failedAddressList.append(ipAddress) g_lock.release()
def getDirectoryList(self, path, keywords="", recursive=False): """ function:give the list of file in the directory input:path, keywords, recursive output:list """ list_Dir = [] try: if keywords == "": if recursive: cmd = "%s -R '%s'" % (g_Platform.getListCmd(), path) (status, output) = subprocess.getstatusoutput(cmd) if status != 0: raise Exception(output + "\nThe cmd is %s" % cmd) list_Dir = output.split('\n') else: list_Dir = os.listdir(path) else: if recursive: cmd = "%s -R '%s' |%s -E '%s'" % ( g_Platform.getListCmd(), path, g_Platform.getGrepCmd(), keywords) else: cmd = "%s '%s' |%s -E '%s'" % ( g_Platform.getListCmd(), path, g_Platform.getGrepCmd(), keywords) (status, output) = subprocess.getstatusoutput(cmd) if status != 0 and output != "": raise Exception(output + "\nThe cmd is %s" % cmd) else: list_Dir = output.split('\n') except Exception as e: raise Exception(ErrorCode.GAUSS_502["GAUSS_50219"] % ( "the list of %s" % path) + " Error:\n%s" % str(e)) while '' in list_Dir: list_Dir.remove('') return list_Dir
def getUserLimits(self, limitType): """ function : Get current user process limits input : string output: string """ limit = g_Platform.getUlimitCmd() limitCmd = "%s -a | %s -F '%s'" % (limit, g_Platform.getGrepCmd(), limitType) (status, output) = subprocess.getstatusoutput(limitCmd) # if cmd failed, then exit if status != 0: raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % limitCmd + " Error:\n%s" % output) return output
def getUsageSize(self, directory): """ get directory or file real size. Unit is byte """ cmd = "" try: cmd = "%s -l -R %s | %s ^- | %s '{t+=$5;} END {print t}'" % ( g_Platform.getListCmd(), directory, g_Platform.getGrepCmd(), g_Platform.getAwkCmd()) (status, output) = subprocess.getstatusoutput(cmd) if (status == 0): return output.split('\t')[0].strip() else: raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd + " Error: \n%s" % str(output)) except Exception as e: raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd)
def chageExpiryInformation(self, user): """ function : Query user password expiration time input : user output: True or False """ changeTemp = g_Platform.getPasswordExpiresCmd(user) changeCmd = "%s | %s -i '^Password expires'" % \ (changeTemp, g_Platform.getGrepCmd()) (status, output) = subprocess.getstatusoutput(changeCmd) # if cmd failed, then exit if status != 0: raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % changeCmd + " Error:\n%s" % output) expireTime = output.split(":")[1] if expireTime.find("never") == 1: return False else: return True