hello sir,

my work is run version.sh file and collect the values of version and type in the output. i have around 500 servers,so i want to automate this process using pyhton. i had written sample code shown below, but it is not giving good results.will you please help me with correct code,

#!/usr/bin/python
import commands
import re

com = "sh version.sh"
output=commands.getoutput("com")
print outpu
result = re.findall(r"versio * | type*",output)
print result
print zip (*[ iter (result) ] *2)
print [tuple (x.strip() for x in y.split (" ")) for y in result]





ouput:

com: command not found
[]
[]
[]

and my version.sh file is like this

Product List
--------------------------------------------------------------------------------
Name                     HTTPD
Version                  6.1.0.0


Installed Product
--------------------------------------------------------------------------------
Type                       PLG
Build Level              b06.14
Build Date               5/16/06

--------------------------------------------------------------------------------
End Status Report
--------------------------------------------------------------------------------

If I understand correctly you're having a problem parsing the return of "version.sh" which looks like the 15-line report. Try this:
Insert after "output=commands.....":

outlist=output.split('\n')
for i in outlist:
   if i.startswith("Version"): vers=i.split()[1]
   if i.startswith("Type"): type=i.split()[1]

Then make your "result=..." however you want to format vers and type.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.