0

I am trying to check for information on Linux server,if it has certain disks named 'ocr'. So I have run a shell command and capture the output in a text file. Then I will search for the string in the file.But this below script doest work.

import os
myCmd = os.popen('ls /dev/asm|grep ocr').read()
print(myCmd)

with open('myCmd') as f:
    if 'ocr' in f.read():
        print("RAC server")
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
vivek
  • 111
  • 7

1 Answers1

0

and capture the output in a text file

You've saved it in a string variable, then you're trying to open and read a file named myCmd. These likely have different content because it's not clear where you've actually written any files

You don't need a file for the logic of that code

if 'ocr' in myCmd:
    print("RAC server")

Also, you really shouldn't be using shell commands if you don't have to

for f in os.listdir("/dev/asm"):
    if "ocr" in f:
        print("RAC server")
        break 
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245