paramiko

How to kill a process on a remote server using python paramiko

不想你离开。 提交于 2019-12-25 03:00:24
问题 I have python script that connects to a remote server with lenny operating system. It runs a process in background using following line: shell.send("cd /my/directory/; nohup ./exec_name > /dev/null 2>&1 &\n") Then after some other codes, it sends a kill command to the server to stop process execution; here's the code: shell.send("kill -9 process_pid \n") It returns no error, but doesn't kill the process and it's still alive in the system. I also tried killall -9 process_name , but I got the

Paramiko recv()/read()/readline(s)() on stderr returns empty string

本秂侑毒 提交于 2019-12-24 14:38:46
问题 I'm using paramiko to collect some information on a remote host and experience issues, when reading ( read() / readline() / readlines() ) from the stderr channel. Sometimes stderr.read() returns an empty string which to me looks like a result of a race condition. However, according to documentation and examples I found on the internet, this seems the exact way to go. I also tried to open a dedicated channel and make use of chan.recv_ready() / chan.recv_stderr_ready() and reading from

Why can't paramiko run this command? (Python)

微笑、不失礼 提交于 2019-12-24 09:30:58
问题 echo Something=Something > file I can use paramiko's exec_command to do cat , grep and ls , but whenever I try to modify a file it does nothing. I already ran su before this. The file remains exactly the same as it was before running the command. 回答1: This is because you have to open a new channel for each exec_command call. This loses the authentication of the su command since it is associated to a specific channel. You have a couple of options. run the command with sudo, which may not be

Python - How do I authenticate SSH connection with Fabric module?

拥有回忆 提交于 2019-12-24 08:49:01
问题 I'm trying to SSH into a Raspberry Pi on a subnet via ethernet using the Fabric module but I can't figure out how to authenticate the connection. My code so far is as follows import fabric c = fabric.Connection(host = "192.168.3.151", port = 22, user = "pi") c.run("touch Desktop/new_file.txt") Obviously I haven't put in my password, "Raspberry", anywhere in the above code to authenticate the SSH connection. I've been trying to understand the Fabric documentation but it's a little beyond me so

Paramiko does not work inside Django when grequests is loaded

…衆ロ難τιáo~ 提交于 2019-12-24 03:54:06
问题 I have a django site. Once page makes use of Grequests. This is preventing any of the other pages that use Paramiko from functioning. How can I get around this? The error it throws is: Error reading SSH protocol bannerThis operation would block forever 来源: https://stackoverflow.com/questions/33041310/paramiko-does-not-work-inside-django-when-grequests-is-loaded

Python pysft/paramiko 'EOF during negotiation' error

陌路散爱 提交于 2019-12-24 01:43:31
问题 I'm using pysftp to download and upload some files. This exact same code I just run an hour before and was fine, but now I got this 'EOF during negotiation' error. What am I missing here? >>> sftp = pysftp.Connection(host, username=user, password=pasw) >>> sftp <pysftp.Connection object at 0x7f88b25bb410> >>> sftp.cd('data') <contextlib.GeneratorContextManager object at 0x7f88b1a86910> >>> sftp.exists(filename) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr

mock paramiko.SSHClient().exec_command()

血红的双手。 提交于 2019-12-24 00:39:54
问题 I need mock execution of some remote command via ssh.exec_command() It returns tuple (stdin, stdout, stderr) as paramiko.ChanelFile object. So, I have output of command as string (which I want, exec_command() to return) and the question how to create ChanelFile object with my output string. Pseudo code: def send_command(self, cmd) self.client.connect(hostname=self.host, username=self.user, password=self.password, timeout=self.timeout) stdin, stdout, stderr = self.client.exec_command(cmd)

python基础之常用模块

六眼飞鱼酱① 提交于 2019-12-24 00:25:39
一 time模块 时间表示形式: 在Python中,通常有这三种方式来表示时间:时间戳、元组(struct_time)、格式化的时间字符串: (1)时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量。我们运行“type(time.time())”,返回的是float类型。 (2)格式化的时间字符串(Format String):'1988-03-16' (3)元组(struct_time):struct_time元组共有9个元素共九个元素:(年,月,日,时,分,秒,一年中第几周,一年中第几天等) # <1> 时间戳 import time print(time.time()) #--------------返回当前时间的时间戳 #1493194473.8422034 # <2> 时间字符串 print(time.strftime("%Y-%m-%d %X")) #2017-04-26 16:14:33 # <3> 时间元组 print(time.localtime()) #东八区时间。 print(time.gmtime()) #标准时间,格林威治时间。 #time.struct_time(tm_year=2017, tm_mon=4, tm_mday=26, tm_hour=16, tm_min=14, tm_sec

I'm trying to understand why I'm getting a “Permission Denied” error when using paramiko 1.7.6

﹥>﹥吖頭↗ 提交于 2019-12-23 22:23:54
问题 Can anyone tell me why I'm getting the following error: Traceback (most recent call last): File "C:\Python27\connect.py", line 22, in <module> sftp.get(filepath, localpath) File "C:\Python27\lib\site-packages\paramiko-1.7.6-py2.7.egg\paramiko\sftp_client.py", line 603, in get fl = file(localpath, 'wb') IOError: [Errno 13] Permission denied: 'C:\\remote' I'm using Python 2.7 on a Windows 7 (as administrator) machine logging into an Ubuntu 10.10 machine. Here is the, very straight forward,

When and why to use load_host_keys and load_system_host_keys?

喜欢而已 提交于 2019-12-23 19:13:04
问题 I am connecting to a host for the first time using its private key file. Do I need to call load_host_keys function before connecting to the host? Or Can I just skip it? I have the autoAddPolicy for missing host key but how can python know the location of the host key file? Hence my question, when to use the function load_host_key? 回答1: Load host keys from a local host-key file. Host keys read with this method will be checked after keys loaded via load_system_host_keys, but will be saved back