【问题标题】:Unable to mount filesystem using python subprocess popen无法使用 python 子进程 popen 挂载文件系统
【发布时间】:2016-04-14 18:56:34
【问题描述】:

我正在尝试使用 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

【问题讨论】:

  • 能否请您添加您将从终端使用的命令行?鉴于代码仅处理变量,并且显示的某些输出与代码 sn-p 无关,这将帮助您获得一个可以适应的解决方案
  • mount: can't find /rsyncTesting/source/share1 in /etc/fstab - 它确实说明了一切......
  • 从 linux 命令行,我正在运行命令:“mount /rsyncTesting/source/share1”,这可以手动正常工作。我在 /etc/fstab 文件中添加文件系统条目,它工作正常,但使用 python 子进程失败。

标签: python linux subprocess popen


【解决方案1】:

我刚刚修改了mount 命令以包含挂载点的名称,
mount /absolute-nas-fs-path /mount-point 而不仅仅是mount /absolute-nas-fs-path

我观察到,在 linux 中,当我们向 /etc/fstab 文件添加条目时,在 shell 中运行 mount <mount point path> 可以正常工作,但在 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]

【讨论】:

    猜你喜欢
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-12
    • 2010-11-11
    • 1970-01-01
    • 2017-08-22
    • 2015-03-03
    相关资源
    最近更新 更多