python - How to count number of strings in a list -


my needs check windows process number.

import sys import os import commands  ip = sys.argv[5] val = sys.argv[1] oid = "host-resources-mib::hrswrunname" cmd = "snmpwalk -v 2c -c public %s %s" % (ip,oid) (r_c,r_e) = commands.getstatusoutput(cmd) if r_c != 0:     print "c - snmpwalk error." else:     in r_e.split('\n'):      =  i.split(':')[-1].strip(' "')     print 

result:

conhost.exe conhost.exe conhost.exe conhost.exe fdhost.exe cmd.exe fdhost.exe 

i hope result is. not know how achieve it.

if sys.argv[1] <5:#count(conhost.exe)     print "critical -" else:     print "ok - " 

how statistics of results? conhost.exe 4 conhost.exe 1 conhost.exe 1

# replace here else:     processes = r_e.split('\n')     programs = 0     program in processes:         programfile = program.split(':')[-1].strip(' "')         # first argument pass program should conhost.exe         if programfile == sys.argv[1]:             programs = programs + 1     if programs < 5 :#count(conhost.exe)         print "critical: running less 5 times:", sys.argv[1]      else:         print "ok" 

second version

# replace here else:     processes = r_e.split('\n')     processes = map(lambda program: program.split(':')[-1].strip(' "'), processes)     if processes.count(sys.argv[1]) < 5 :#count(conhost.exe)         print "critical: running less 5 times:", sys.argv[1]      else:         print "ok" 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -