paramiko

Piped commands in paramiko

时光怂恿深爱的人放手 提交于 2019-12-07 04:10:03
问题 How do I run piped commands in paramiko? I'm doing this: statement = 'grep thing file | grep thing2 | tail -1' last_msg = conn.execute(statement) and I get the output of grep thing file only. 回答1: Because grep doesn't know how to handle | . Get ready for some nasty escaping: statement = """sh -c 'grep thing file | grep thing2 | tail -1'""" This creates a shell on the other side, and asks it to interpret the string grep thing file | grep thing2 | tail -1 . The single quotes are necessary since

Passing a Paramiko connection SFTPFile as input to a dask.dataframe.read_parquet

你说的曾经没有我的故事 提交于 2019-12-06 22:10:39
I tried to pass class paramiko.sftp_file.SFTPFile instead of file URL for pandas.read_parquet and it worked fine. But when I tried the same with Dask, it threw an error. Below is the code I tried to run and the error I get. How can I make this work? import dask.dataframe as dd import parmiko ssh=paramiko.SSHClient() sftp_client = ssh.open_sftp() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) source_file=sftp_client.open(str(parquet_file),'rb') full_df = dd.read_parquet(source_file,engine='pyarrow') print(len(full_df)) Traceback (most recent call last): File "C:\Users\rrrrr\Documents

How to see (log) file transfer progress using paramiko?

不问归期 提交于 2019-12-06 19:29:38
问题 I'm using Paramiko's SFTPClient to transfer file between hosts. I want my script to print the file transfer progress similar to the output seen using scp. $ scp my_file user@host user@host password: my_file 100% 816KB 815.8KB/s 00:00 $ Any idea? Thanks in advance 回答1: Use the optional callback parameter of the put function. Something like this: def printTotals(transferred, toBeTransferred): print "Transferred: {0}\tOut of: {1}".format(transferred, toBeTransferred) sftp.put("myfile",

Executing SFTP commands using Paramiko in Python

瘦欲@ 提交于 2019-12-06 16:58:43
问题 I want to connect to SFTP server and execute commands, like ls . But I'm getting an error: paramiko.ssh_exception.SSHException: Unable to open channel. import paramiko import pysftp ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('xxxxxxxx', username='xxxxxxx', password='xxxxxxxx', key_filename='xxxxxxxxxxx') stdin, stdout, stderr = ssh.exec_command('ls') print stdout.readlines() ssh.close() exit() 回答1: Answer to my problem is as follow: how to

Pass Python variable inside command with Paramiko

為{幸葍}努か 提交于 2019-12-06 16:44:29
With this command, I want to save an output of the smartctl command of the sda drive. Now, since I use RAID, I have multiple drives, not just sda. The following command works fine: stdin, stdout, stderr = ssh.exec_command('/bin/su root -c "smartctl -a /dev/sda > /tmp/smartctl_output1"', get_pty=True) # ORIGINAL I want to achieve that I pass local Python variable "DISK" containing sda, sdb, sdc and so on instead only static value. The following line produces error: stdin, stdout, stderr = ssh.exec_command('/bin/su root -c "smartctl -a /dev/" + DISK + " > /tmp/" + DISK', get_pty=True) edit:

Process dies, if it is run via paramiko ssh session and with “&” in the end

让人想犯罪 __ 提交于 2019-12-06 15:53:57
问题 I just want to run tcpdump in background using paramiko. Here is the part of the code: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(host, username=login, password=password) transport = ssh.get_transport() channel = transport.open_session() channel.get_pty() channel.set_combine_stderr(True) cmd = "(nohup tcpdump -i eth1 port 443 -w /tmp/dump20150317183305940107.pcap) &" channel.exec_command(cmd) status = channel.recv_exit_status() After I

Paramiko sftp put request getting terminated with EOFError() in python

僤鯓⒐⒋嵵緔 提交于 2019-12-06 15:23:12
问题 I'm trying to upload couple of .zip files with size ranging between 20 to 30 MBs using python's sftp module 'Paramiko'. I'm able to successfully connect to the sftp server, and also able to list the contents in the destination directory. But while attempting to upload files from my ec2 linux machine, the request is taking too much time and then terminating with EOFError(). Below is the code, >>> import paramiko >>> import os >>> ftp_host='*****' >>> ftp_username='***' >>> ftp_password='**' >>

Unable to see ifconfig output using paramiko

血红的双手。 提交于 2019-12-06 15:22:02
I am using below code to execute commands on a remote machine, import paramiko import os dssh = paramiko.SSHClient() dssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) dssh.connect('192.168.1.5', username='root', password='asdfghhh') import os stdin, stdout, stderr = dssh.exec_command('ls') print stdout.read() stdin, stdout, stderr = dssh.exec_command('ifconfig') print stdout.read() stdin, stdout, stderr = dssh.exec_command('ps') print stdout.read() dssh.close() when I execute the program, Its able to show the ls and ps as well as other commands output. however ifconfig o/p is not

multithreading for paramiko

假如想象 提交于 2019-12-06 14:49:19
Context If have a script that connects to servers and then curls the localhost for the information I need Issue My issue is that I have around 200 servers I need to grab information from, the method I use, takes about 15 minutes to finish, which isn't bad but the stuff I'm wanting to do is more advanced and if I can nail multithreading I can achieve more. Desired Outcome I just want to have a threadpool of 5-10 workers so I can grab the information I need quicker. Code from Queue import Queue from multiprocessing.pool import ThreadPool import threading, os, sys import socket from threading

How to get each dependent command execution output using Paramiko exec_command

末鹿安然 提交于 2019-12-06 14:42:27
问题 I'm using Paramiko in order to execute a single or a multiple commands and get its output. Since Paramiko doesn't allow executing multiple commands on the same channel session I'm concatenating each command from my command list and executing it in a single line, but the output can be a whole large output text depending on the commands so it's difficult to differentiate which output is for each command. ssh.exec_command("pwd ls- l cd / ls -l") I want to have something like: command_output = [(