挂载磁盘脚本

  1. #!/usr/bin/python
  2. #coding=utf-8
  3. '''
  4. Created on Nov 4, 2015
  5. install basic system [c2]
  6. @author: Galbraith
  7. '''
  8. from subprocess import call
  9. from os.path import basename
  10. import os
  11. import sys
  12. import commands
  13. def scall(cmd_line):
  14. '''linux shell '''
  15. return call(cmd_line,shell=True)
  16. def findstrinfile(filename, lookup):
  17. '''file str differ check'''
  18. return lookup in open(filename,'rt').read()
  19. def file_check(file_sl):
  20. '''file differ check'''
  21. return os.path.isfile(file_sl)
  22. def dir_check(dir_sl):
  23. '''dir differ check'''
  24. return os.path.exists(dir_sl)
  25. def srun(comm):
  26. '''system command'''
  27. return os.system(comm)
  28. def mount_disk():
  29. '''mount new disk'''
  30. srun('mkdir /data')
  31. srun('mkfs -t ext4 /dev/vdb')
  32. srun('mount /dev/vdb /data')
  33. srun('echo "/dev/vdb /data ext4 defaults 0 0" >> /etc/fstab')
  34. def cat_mount():
  35. mount = commands.getoutput('mount -v')
  36. lines = mount.split('\n')
  37. points = map(lambda line: line.split()[2], lines)
  38. srun('df -h')
  39. print points
  40. def handle():
  41. mount_disk()
  42. cat_mount()
  43. if __name__ == '__main__':
  44. handle()
posted @ 2020-07-17 14:33  技术颜良  阅读(290)  评论(0编辑  收藏  举报