python - 如何使用python挂载网络目录?

标签 python linux scripting mount

我需要在 linux 机器上使用 python 在网络机器“data”上挂载目录“dir”

我知道我可以通过命令行发送命令:

mkdir ~/mnt/data_dir
mount -t data:/dir/ ~/mnt/data_dir

但是我如何从 python 脚本发送这些命令?

最佳答案

我建议您使用 subprocess.checkcall

from subprocess import *

#most simply
check_call( 'mkdir ~/mnt/data_dir', shell=True )
check_call( 'mount -t whatever data:/dir/ ~/mnt/data_dir', shell=True )


#more securely
from os.path import expanduser
check_call( [ 'mkdir', expanduser( '~/mnt/data_dir' ) ] )
check_call( [ 'mount', '-t', 'whatever', 'data:/dir/', expanduser( '~/mnt/data_dir' ) ] )

关于python - 如何使用python挂载网络目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2232420/

相关文章:

python - 如何在 python 中制作帕累托图?

python - 如何防止 HoughLines 多次检测某些行

c - Linux 上 accept() 的段错误

python - pandas 数据框中 df.loc 第一个参数的范围和单个值之间的差异

python - tkinter 设置比例(创建 2x2 框)

scala - 如何让 "scalas"脚本运行程序更安静?

mysql - 将列名转换为小写的 MYSQL 脚本

javascript - 单击按钮获取列表中选中复选框的 ID

c - linux pthread 在指定时间循环运行(避免信号)

linux - linux shell中 "-newer $file"命令的 "find"选项是如何工作的?