Correct my Code

import subprocess
from symbol import with_stmt

f = open(“mailoutput.txt”, “w+”)
with_stmt:(“agtoutput.txt”, “w”) as output:
subprocess.run(["/u01/opt/HP/BSM/opr/bin/opr-agt -username admin -password omiadmin -node_group /DUT_HPUX -status"],
stdout=output);
with(“agtoutput.txt”, “w+”) as output:
subprocess.run(
["/u01/opt/HP/BSM/opr/bin/opr-agt -username admin -password omiadmin -node_group /DUT_LINUX -status"],
stdout=output);
with(“mailoutput.txt”, “w”) as mailOutput:
subprocess.run([“cat /tmp/agtoutput |grep :383: |awk ‘{print $1}’ |sed ‘s/:.*//’ >/tmp/pingNode”],
stdout=mailOutput);
print(“OMI Unix Agent Error Message”)
print("===============================")
f = open(“agtoutput.txt”, “r”)
errorStringArr = [“isn’t running”, “OpC40-428”, “ERROR”, “Stopped”, “Aborted”]
errorNode =
errCount = 0
nullcount = 0
nodeCount = 0

for x in f:
if ‘:383:’ in x or x == ‘’:
print('This will be omitted ’ + x)
nullcount += 1
else:
for errString in errorStringArr:
if errString in x:
errorNode.append(x)
errCount += 1
break
nodeCount += 1
f.close()
print(str(nullcount))
print(‘Openview agent is not running on: :’ + str(errorNode))
print('Error count : ’ + str(errCount))
print(‘Node count :’ + str(nodeCount + errCount))

f.close();

Hello Vinay,

First: “Correct my code” implies that something is wrong with it. You have not specified what is wrong - the output is not as expected, the code results in an error and/or traceback, it runs but produces no output or whatever. As we cannot run it we just can’t know. Please add this to your question.

Second: In Python indentation is key to understanding your program, for Python itself and the human reader. I think you used the online editor to create the message. Use the blockquote to include the formatting of the program text.

Third: a short description of what your program is for may well increase the grasp of the reader of why things are done as they are done.

Changing these three things will greatly improve your chances of getting useful help.

Hello Mholscher,
Thank you for reply…
I was trying to write a program as below subject;
“script in python which should do " checking OVO status in unix/linux server and OMi status in windows server” and send a mail.
If suppose OVO/OMi status is not running in the server, then it should provide the server name
and Finally printing the count of all server which status in running and count of servers which status is not running…"

so if could help me, it will be greatful…

That is one of three.

I inspected your subprocess.run statement, as it looked suspicious. From the documentation:

The full function signature is largely the same as that of the Popen constructor - most of the arguments to this function are passed through to that interface. ( timeout , input , check , and capture_output are not.)

Going to the Popen documentation we find:

args should be a sequence of program arguments or else a single string or path-like object. By default, the program to execute is the first item in args if args is a sequence. If args is a string, the interpretation is platform-dependent and described below. See the shell and executable arguments for additional differences from the default behavior. Unless otherwise stated, it is recommended to pass args as a sequence.

An example of passing some arguments to an external program as a sequence is:

Popen(["/usr/bin/git", “commit”, “-m”, “Fixes a bug.”])

On POSIX, if args is a string, the string is interpreted as the name or path of the program to execute. However, this can only be done if not passing arguments to the program.

The first argument passed to subprocess.run should be a sequence of arguments, because the first one is not a command line, but the path to the program.

Btw, Openview is a tool marketed by HP Enterprise. You can also get support for the product by them.