标题: [技术讨论] python3 ubuntu 自动挂载u盘 [打印本页]
作者: Gin_Q 时间: 2020-9-4 10:09 标题: python3 ubuntu 自动挂载u盘
- #!/usr/bin/env python3
- #coding=utf-8
-
- import os
- import re
- import shutil
-
- def mount_u():
- '''
- # mount U Disk to /mnt
- '''
- os.system('echo "\033[32mMount U Disk To /mnt\033[0m"')
- if not os.path.isdir(r'/mnt'): os.mkdir(r'/mnt')
- #check u disk is mount to mnt
- if os.system('mountpoint -q /mnt') == 0:
- print('/mnt is exist, umount /mnt')
- os.system('umount /mnt')
- fdisk = os.popen('fdisk -l')
- mode = re.compile(r'/dev/sd[b-z]1')
- u_path = re.search(mode, fdisk.read())
- if u_path:
- print('U Disk: {}'.format(u_path.group()))
- if os.system('mount ' + u_path.group() + ' /mnt') == 0:
- print('U Disk mounted successfully')
- else:
- print('U Disk mounting failed')
- else:
- print('U Disk: {}'.format('NO Find!'))
-
- if __name__ == '__main__':
- mount_u()
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |