#!/usr/bin/python2 import os import sys cmd="cp -f /etc/fstab /etc/fstab.backup.pre_acl" os.system(cmd) f = open('/etc/fstab', 'r') fstab=f.readlines() f.close() mp='/data/mnt/d1' def check_fstab_mount(): #first check if media/d1 is in list, if not add it. newfstab=[] mnt_in_fstab=False for line in fstab: split_line=line.split() try: if split_line[1] == mp : print "found mountpoint if fstab" mnt_in_fstab = True break except: pass return mnt_in_fstab def add_mnt_to_fstab(): newfstab=[] for line in fstab: newfstab.append(line) split_line=line.split() try: if split_line[1] == "/myth": split_line[1] = mp new_line='\t'.join(split_line)+"\n" newfstab.append(new_line) except: pass return newfstab if check_fstab_mount() == False: print "I need to add it" newfstab=add_mnt_to_fstab() f = open('/tmp/fstab', 'w') for i in newfstab: f.write(i) #f.write("\n") f.close()