0
import subprocess

def volumeCheck(volume_name):
    """This function will check volume name is mounted or not.
    """
volume_name = raw_input('Enter volume name:')
volumeCheck(volume_name) 

p = subprocess.Popen(['df', '-h'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p1, err = p.communicate()
pattern = p1

new_vol = '/VolumeData/' '+ volume_name +'

if pattern.find(new_vol) != -1 :

    print 'volume mounted'

else:
    print 'volume not mounted'

new_vol = '/VolumeData/' '+ volume_name +' i think this is wrong , but how can i do this ..?

i like to search \volumeData\ volume_name .

root@sr-query:/# df -h
Filesystem            Size  Used Avail Use% Mounted on
rootfs                938M  473M  418M  54% /
/dev/md0              938M  473M  418M  54% /
none                  250M  4.9M  245M   2% /dev
/dev/md2              9.7M  1.2M  8.0M  13% /usr/config
/dev/md7              961M   18M  895M   2% /downloads
tmpfs                 250M  7.9M  242M   4% /var/volatile
tmpfs                 250M     0  250M   0% /dev/shm
tmpfs                 250M     0  250M   0% /media/ram
/dev/mapper/vg9-lv9  1016M   65M  901M   7% /VolumeData/sp
/dev/mapper/vg10-lv10
                     1016M   65M  901M   7% /VolumeData/cp
root@sr-query:/# 

Thanks in adavnce

2
  • its working fine now :) hope this is not optimized becoz am a beginer in python...any optimization help me more thanks oyss Commented Oct 18, 2012 at 12:36
  • if you have managed to answer your own question it's good etiquette to write it down here. That way people will know you dont need an answer anymore, and maybe your answer will be useful to someone else Commented Oct 18, 2012 at 19:26

1 Answer 1

1

What exactly are you going for? If I understand properly, I would probably try os.path.join, e.g.:

new_vol = os.path.join('/','VolumeData', volume_name)

Also, since you're not actually using the result of find, you might want to consider:

if new_vol in p1:

instead.

Sign up to request clarification or add additional context in comments.

1 Comment

i need to check this directory(/VolumeData/) contain my enterd volume_name mounted or not...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.