相关疑难解决方法(0)

等到通过Python在远程计算机上完成任务

我在Ubuntu上用python编写程序.在该程序中,我尝试在连接到网络的远程计算机(RaspberryPi)上完成"删除文件"任务后打印一条消息.

但在实际操作中,打印命令不会等到远程机器上的任务完成.

任何人都可以指导我如何做到这一点?我的编码如下

import paramiko

# Connection with remote machine
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('192.168.2.34', username='pi', password='raspberry')

filename   = 'fahad.txt'
filedelete ='rm ' + filename
stdin, stdout, stderr = client.exec_command(filedelete)
print ("File Deleted")
client.close()
Run Code Online (Sandbox Code Playgroud)

python remote-access paramiko python-2.7

9
推荐指数
2
解决办法
2万
查看次数

基本的paramiko exec_command帮助

我是一个新的paramiko用户,并且很难在paramiko的远程服务器上运行命令.我想导出路径并运行tophat在后台调用的程序.我可以登录,paramiko.sshclient()但我的代码exec_command没有结果.

stdin, stdout, sterr = ssh.exec_command('export PATH=$PATH:/proj/genome/programs
/tophat-1.3.0/bin:/proj/genome/programs/cufflinks-1.0.3/bin:/proj/genome/programs/
bowtie-0.12.7:/proj/genome/programs/samtools-0.1.16')

stdin, stdout, sterr = ssh.exec_command('nohup tophat -o /output/path/directory -I 
10000 -p 8 --microexon-search -r 50 /proj/genome/programs/bowtie-0.12.7/indexes
/ce9 /input/path/1 /input/path/2 &')
Run Code Online (Sandbox Code Playgroud)

没有nohup.out文件和python只是转到下一行没有错误消息.我试过没有nohup,结果是一样的.我试图遵循这个paramiko教程.

我使用exec_command不正确吗?

python paramiko

7
推荐指数
2
解决办法
3万
查看次数

Paramiko ssh 死/挂,输出大

我尝试使用 Paramiko 和 ssh 来备份服务器以调用tar命令。当文件数量有限时,一切正常,但当文件夹很大时,脚本会无休止地等待。下面的测试告诉我问题出在标准输出的大小上。

有没有办法纠正它并执行这种命令?

案例大输出:

query = 'cd /;ls -lshAR -h'
chan.exec_command(query)
while not chan.recv_exit_status():
    if chan.recv_ready():
        data = chan.recv(1024)
        while data:
            print data
            data = chan.recv(1024)

    if chan.recv_stderr_ready():
        error_buff = chan.recv_stderr(1024)
        while error_buff:
            print error_buff
            error_buff = chan.recv_stderr(1024)
    exist_status = chan.recv_exit_status()
    if 0 == exist_status:
        break
Run Code Online (Sandbox Code Playgroud)

结果是(不行 - 阻止 - 死??)

query = 'cd /;ls -lshAR -h'
chan.exec_command(query)
while not chan.recv_exit_status():
    if chan.recv_ready():
        data = chan.recv(1024)
        while data:
            print data
            data = chan.recv(1024)

    if chan.recv_stderr_ready(): …
Run Code Online (Sandbox Code Playgroud)

python ssh paramiko

5
推荐指数
1
解决办法
2234
查看次数

标签 统计

paramiko ×3

python ×3

python-2.7 ×1

remote-access ×1

ssh ×1