The main paramiko exec_command help

I am a new paramiko user and am having difficulty running commands on a remote server with paramiko. I want to export the path, and also run a program called tophatin the background. I can log in using paramiko.sshclient(), but my code exec_commandhas no results.

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 &')

there is no file nohup.out, and python just moves on to the next line without error messages. I tried without nohup, and the result is the same. I tried to follow this paramic textbook .

Am I using it wrong exec_command?

+5
source share
4 answers

exec_command() , , Python .

, .

"time.sleep(10)" , " ". , ChannelFile stdout stdout.readlines(), , , , , .

, 2 exec_command, exec. , .

demos, Channel, API / , exec.

+5

, recv_exit_status() . :

import paramiko;
import time;

cli = paramiko.client.SSHClient();
cli.set_missing_host_key_policy(paramiko.client.AutoAddPolicy());
cli.connect(hostname="10.66.171.100", username="mapping");
stdin_, stdout_, stderr_ = cli.exec_command("ls -l ~");
# time.sleep(2);    # Previously, I had to sleep for some time.
stdout_.channel.recv_exit_status();
lines = stdout_.readlines();
for line in lines:
    print line;

cli.close();

, . , .

+1

.

stdin, stdout, stderr = ssh.exec_command('sleep 10; hostname')

10

0

bash_profile . " ".

, command = 'mysqldump -uu -pp -h1.1.1.1 -P999 table > table.sql' Mysql

Then I need to load the bash_profile file before this reset command by typing . ~/.profile; .~/.bash_profile;.

Example

my_command  = 'mysqldump -uu -pp -h1.1.1.1 -P999 table > table.sql;'

pre_command = """
. ~/.profile;
. ~/.bash_profile;
"""

command = pre_command + my_command

stdin, stdout, stderr = ssh.exec_command(command)
-1
source

All Articles