我正在尝试使用 python subprocess.popen 命令挂载 nas 文件系统,我正在运行一个脚本来挂载文件系统。一些脚本无法挂载文件系统的原因。
我的脚本:
self.mountSrc = subprocess.Popen('mount'+' '+ self.src_m[l], shell=True)
print self.mountSrc
if self.mountSrc==0:
print "Mounted filesystem:"+ self.src_m[l]
我的脚本输出:
Mounting: Source Mount Point:/rsyncTesting/source/share1
Starting:[................................................... ] Done!
mount: can't find /rsyncTesting/source/share1 in /etc/fstab or /etc/mtab
1
在运行 mount 命令之前,我正在更新/etc/fstab 中的文件系统路径。我也可以从命令行以 root 用户身份手动挂载文件系统。
slcnas888:/export/rsyncScriptProject_Source/rsyncShare1/.zfs/snapshot/SR_0000-0000000_Refresh_rsyncShares_RSYNC_PROJ_exp13April16/rsyncTesting/source/share1
最佳答案
我刚刚修改了 mount
命令包含挂载点的名称,
即 mount /absolute-nas-fs-path /mount-point
而不仅仅是 mount /absolute-nas-fs-path
.
我观察到在 Linux 中,当我们向 /etc/fstab
添加条目时文件,正在运行 mount <mount point path>
在 shell 中工作正常,但在 python 子进程中,我们需要在命令参数中传递文件系统绝对路径和挂载点。
# self.src_fs[l] is an item from my list of filesystem paths.
# self.src_m[l] is an item from my list of mount points.
self.mountSrc = subprocess.Popen('mount ' + self.src_fs[l] + ' ' + self.src_m[l], shell = True)
print self.mountSrc
if self.mountSrc == 0:
print "Mounted filesystem:" + self.src_m[l]
关于python - 无法使用python子进程popen挂载文件系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36631680/