Python Paramiko脚本和;RPC:远程系统错误“;
我正在编写一个Python脚本,让本地Ubuntu机器通过Paramiko连接到远程linux机器(在同一本地网络上),然后使用Python Paramiko脚本和;RPC:远程系统错误“;,python,ssh,paramiko,mount,nfs,Python,Ssh,Paramiko,Mount,Nfs,我正在编写一个Python脚本,让本地Ubuntu机器通过Paramiko连接到远程linux机器(在同一本地网络上),然后使用exec_command()执行mount-t nfs-o tcp,nolock:/path/to/local/directory/path/to/remote/directory命令 但是,当我运行脚本时,它将在mount命令处挂起一段时间,stderrreturnbyexec\u command()显示以下错误: mount: RPC: Remote system
exec_command()
执行mount-t nfs-o tcp,nolock:/path/to/local/directory/path/to/remote/directory
命令
但是,当我运行脚本时,它将在mount命令处挂起一段时间,stderr
returnbyexec\u command()
显示以下错误:
mount: RPC: Remote system error - Connection refused
mount: mounting <local machine ip>:/path/to/local/directory on /path/to/remote/directory failed: Bad file descriptor
最后,以下是我的代码:
def executeCMD(sshC, setupCMD, hostCMD, scpCMD, cleanCMD):
confirm = ''
for cmd in setupCMD:
if cmd.startswith('rm -r'):
while confirm not in ['y', 'n']:
confirm = (
input('Command to execute: "{}" Are you sure?(y/n) '.format(cmd))
.strip()
.lower()
)
if confirm == 'y':
stdin, stdout, stderr = sshC.exec_command(cmd)
logger.info('{} (Recv: {})'.format(cmd,
stderr.read().decode()))
for cmd in hostCMD:
cmdOut = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True)
out = cmdOut.stdout.read().decode()
logger.info('{}'.format(out))
for cmd in scpCMD:
scpC = SCPClient(sshC.get_transport())
scpC.put(*cmd)
elif confirm == 'n':
for cmd in cleanCMD:
stdin, stdout, stderr = sshC.exec_command(cmd)
logger.info('{} (Recv: {})'.format(cmd,
stderr.read().decode()))
return 1
else:
stdin, stdout, stderr = sshC.exec_command(cmd)
logger.info('{} (Recv: {})'.format(cmd,
stderr.read().decode()))
return 0
我想知道是否有人也有同样的问题?+1询问与编程和开发有关的SSH问题。尝试使用
子流程
和sshpass-p SSH
作为解决方法,但仍然显示相同的错误。我越来越糊涂了……好吧,我试了几次子流程
+sshpass-p…
,终于让它工作了。奇怪的是,它只是第一次失败,你只需要重试一次就可以让它工作。但是等待第一个faiilure 2分钟太烦人了,所以我想我会做更多的研究。+1问一个与编程和开发有关的SSH问题。尝试使用子进程
和sshpass-psh
作为解决方法,但仍然显示出相同的错误。我越来越糊涂了……好吧,我试了几次子流程
+sshpass-p…
,终于让它工作了。奇怪的是,它只是第一次失败,你只需要重试一次就可以让它工作。但是等第一个诱惑2分钟太烦人了,所以我想我会做更多的研究。
def executeCMD(sshC, setupCMD, hostCMD, scpCMD, cleanCMD):
confirm = ''
for cmd in setupCMD:
if cmd.startswith('rm -r'):
while confirm not in ['y', 'n']:
confirm = (
input('Command to execute: "{}" Are you sure?(y/n) '.format(cmd))
.strip()
.lower()
)
if confirm == 'y':
stdin, stdout, stderr = sshC.exec_command(cmd)
logger.info('{} (Recv: {})'.format(cmd,
stderr.read().decode()))
for cmd in hostCMD:
cmdOut = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True)
out = cmdOut.stdout.read().decode()
logger.info('{}'.format(out))
for cmd in scpCMD:
scpC = SCPClient(sshC.get_transport())
scpC.put(*cmd)
elif confirm == 'n':
for cmd in cleanCMD:
stdin, stdout, stderr = sshC.exec_command(cmd)
logger.info('{} (Recv: {})'.format(cmd,
stderr.read().decode()))
return 1
else:
stdin, stdout, stderr = sshC.exec_command(cmd)
logger.info('{} (Recv: {})'.format(cmd,
stderr.read().decode()))
return 0