Python “通过paramiko安装失败”;没有这样的文件或目录;
我正在使用python的paramiko操作远程linux机器的访问。我的命令“mount device dir”由于“没有这样的文件或目录”而失败,即使当我远程使用它时(通过ssh连接,而不是通过paramiko连接),完全相同的命令也会成功 我尝试将/etc/fstab更改为一些值,同样的情况。一旦我通过ssh-ok输入它,同样的命令通过paramiko-over错误消息 有什么想法吗 命令示例(从原点最小更改): 给我一个错误:Python “通过paramiko安装失败”;没有这样的文件或目录;,python,paramiko,Python,Paramiko,我正在使用python的paramiko操作远程linux机器的访问。我的命令“mount device dir”由于“没有这样的文件或目录”而失败,即使当我远程使用它时(通过ssh连接,而不是通过paramiko连接),完全相同的命令也会成功 我尝试将/etc/fstab更改为一些值,同样的情况。一旦我通过ssh-ok输入它,同样的命令通过paramiko-over错误消息 有什么想法吗 命令示例(从原点最小更改): 给我一个错误: mount /dev/sda1 failed: mount
mount /dev/sda1 failed: mount: mounting /dev/sda1 on /media/card failed: No such file or directory
/etc/fstab中的内容:
/dev/sda1 /media/card vfat fmask=0000,dmask=0000 0 0
当然,/media/card目录存在。同样,我可以通过ssh手动使用上面的命令,它可以正常工作
更新。
同时,我尝试了python的fabric库(构建于paramiko之上),完全如中所述
直接给我与paramiko完全相同的错误信息
更新2。好的,作为一个解决方法,我使用直接ssh调用挂载驱动器,如下面评论中所建议的。在代码中完成任何必要的操作后,我尝试使用“正常”paramiko调用卸载驱动器:
self.ssh.exec_command("/bin/umount /dev/sda1")
它是有效的。所以现在我完全迷路了,上面的挂载失败了,但卸载工作正常。这真奇怪
更新3。我已尝试将LD_LIBRARY_PATH额外设置为mount库的位置,它需要libm.so.6和libc.so.6,两者都位于/lib中,如:
self.ssh.exec_command("export LD_LIBRARY_PATH=/lib:/usr/lib && /bin/mount /dev/sda1")
但是没有再次成功。我能够让它工作(初稿。另外,我对python还是新手)。不管怎么说,这是我的代码片段 对我来说最大的障碍是,windows主机名中似乎有4->1反斜杠的要求 首先确保您拥有windows PC的共享。在本例中,我的计算机/共享名为“COMP_name/share_name” 提供的用户名/密码是访问共享的窗口凭据
import sys
import paramiko
import constant
### START ###############################################################################
# connect to a GW device
# GW: hostname to connect to
# return: client connection object
def connectToClient(GW):
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(GW, username=constant.GW_USER, password=constant.GW_PASS)
except:
print("Unexpected error:", sys.exc_info()[0])
return None
return client
### END ################################################################################
### START ###############################################################################
# execute a command on the remote device
# client: client connection object to the GW
# cmd: the command to execute
# eg. 'ls -l'
# return: nothing (TODO: maybe return error info)
def exec(client, cmd):
stdin, stdout, stderr = client.exec_command(cmd)
for line in stdout:
print(line.strip('\n'))
#for line in stderr:
# print(line.strip('\n'))
return
### END #################################################################################
# other stuff
# .
# .
# .
##########################################
# Start - upload the self extracting file to the GW
##########################################
#create the mount point
exec(client, "sudo mkdir /mnt/remote_files")
#mount the source directory (4 to 1 for the back slash chars in the UNC address ...)
exec(client, "sudo mount -t cifs -o username=oxxxxxxp,password=cxxxxxxxxx0 \\\\\\\\COMP_NAME\\\\SHARE_NAME /mnt/remote_files")
#copy the script file
exec(client, "cp /mnt/remote_files/selfextract.bsx rtls/scripts/selfextract.bsx")
#unmount the remote source
exec(client, "sudo umount /mnt/remote_files")
##########################################
# Done - upload the self extracting file to the GW
##########################################
# other stuff
# .
# .
# .
希望这对某人有帮助
Pat我能够让它工作(初稿。另外,我对python还是新手)。不管怎么说,这是我的代码片段 对我来说最大的障碍是,windows主机名中似乎有4->1反斜杠的要求 首先确保您拥有windows PC的共享。在本例中,我的计算机/共享名为“COMP_name/share_name” 提供的用户名/密码是访问共享的窗口凭据
import sys
import paramiko
import constant
### START ###############################################################################
# connect to a GW device
# GW: hostname to connect to
# return: client connection object
def connectToClient(GW):
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(GW, username=constant.GW_USER, password=constant.GW_PASS)
except:
print("Unexpected error:", sys.exc_info()[0])
return None
return client
### END ################################################################################
### START ###############################################################################
# execute a command on the remote device
# client: client connection object to the GW
# cmd: the command to execute
# eg. 'ls -l'
# return: nothing (TODO: maybe return error info)
def exec(client, cmd):
stdin, stdout, stderr = client.exec_command(cmd)
for line in stdout:
print(line.strip('\n'))
#for line in stderr:
# print(line.strip('\n'))
return
### END #################################################################################
# other stuff
# .
# .
# .
##########################################
# Start - upload the self extracting file to the GW
##########################################
#create the mount point
exec(client, "sudo mkdir /mnt/remote_files")
#mount the source directory (4 to 1 for the back slash chars in the UNC address ...)
exec(client, "sudo mount -t cifs -o username=oxxxxxxp,password=cxxxxxxxxx0 \\\\\\\\COMP_NAME\\\\SHARE_NAME /mnt/remote_files")
#copy the script file
exec(client, "cp /mnt/remote_files/selfextract.bsx rtls/scripts/selfextract.bsx")
#unmount the remote source
exec(client, "sudo umount /mnt/remote_files")
##########################################
# Done - upload the self extracting file to the GW
##########################################
# other stuff
# .
# .
# .
希望这对某人有帮助
Pat你能分享命令和你的paramiko代码吗?我为Clarity在/etc/fstab中添加了一个最小的示例和一个错误和行。我没有足够的
mount
经验来给出明确的答案。--但根本原因很可能与这里相同:----testdoingsshroot@192.168.1.1mount/dev/sda1
我不是指mount
的路径(您的编辑/bin/mount
)——我指的是一个概要文件的效果。您是否按照我的建议测试了ssh
命令?即使您的新代码也显示IP192.168.1.1
,当您的ssh
测试使用192.168.201.220
时,您可以共享命令和您的paramiko代码吗?我为Clarity在/etc/fstab中添加了一个最小的示例以及一个错误和行。我没有足够的mount
经验来给出明确的答案。--但根本原因很可能与这里相同:----testdoingsshroot@192.168.1.1mount/dev/sda1
我不是指mount
的路径(您的编辑/bin/mount
)——我指的是一个概要文件的效果。您是否按照我的建议测试了ssh
命令?即使您的新代码显示IP192.168.1.1
,而ssh
测试使用192.168.201.220
。
import sys
import paramiko
import constant
### START ###############################################################################
# connect to a GW device
# GW: hostname to connect to
# return: client connection object
def connectToClient(GW):
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(GW, username=constant.GW_USER, password=constant.GW_PASS)
except:
print("Unexpected error:", sys.exc_info()[0])
return None
return client
### END ################################################################################
### START ###############################################################################
# execute a command on the remote device
# client: client connection object to the GW
# cmd: the command to execute
# eg. 'ls -l'
# return: nothing (TODO: maybe return error info)
def exec(client, cmd):
stdin, stdout, stderr = client.exec_command(cmd)
for line in stdout:
print(line.strip('\n'))
#for line in stderr:
# print(line.strip('\n'))
return
### END #################################################################################
# other stuff
# .
# .
# .
##########################################
# Start - upload the self extracting file to the GW
##########################################
#create the mount point
exec(client, "sudo mkdir /mnt/remote_files")
#mount the source directory (4 to 1 for the back slash chars in the UNC address ...)
exec(client, "sudo mount -t cifs -o username=oxxxxxxp,password=cxxxxxxxxx0 \\\\\\\\COMP_NAME\\\\SHARE_NAME /mnt/remote_files")
#copy the script file
exec(client, "cp /mnt/remote_files/selfextract.bsx rtls/scripts/selfextract.bsx")
#unmount the remote source
exec(client, "sudo umount /mnt/remote_files")
##########################################
# Done - upload the self extracting file to the GW
##########################################
# other stuff
# .
# .
# .