我正在尝试写一个python脚本来检查“父”挂载点在“子”挂载点之前是否存在,例如/mnt应该在/mnt/mount1之前
这是我到目前为止所写的内容
#!/usr/bin/python
for line in open("/etc/fstab", "r"):
line = line.strip()
if line == "":
continue
lintyp = linetype(line)
if lintyp >= type:
type = lintyp使用python或甚至bash
发布于 2016-02-15 04:11:17
你可以用fstab模块,我用StringIO.StringIO代替了open('/etc/fstab', 'r'):
import StringIO
from fstab import Fstab
s = content = """\
# this is a comment, followed by an empty line
# the next line is a syntax error
yo!
#UUID="2b0ab63e-fd1b-4d7a-b021-3827b4aa4c8b" /media/hda3 ext3 defaults 0 2
/dev/hda2 /boot ext3 defaults 0 2
/dev/hda1 / ext3 defaults,errors=remount-ro 0 1
"""
fstab = Fstab()
#fstab.read(open('/etc/fstab', 'r'))
fstab.read(StringIO.StringIO(content))
output = []
_fs = []
for line in fstab.lines:
if line.has_filesystem():
_fs.append(line.raw)
else:
output.append(line.raw)
_fs = sorted(_fs)
output.extend(_fs)
output = '\n'.join(line for line in output)
print output
#You have just to write to '/etc/fstab' https://stackoverflow.com/questions/35395642
复制相似问题