Pipeline teams in Paramiko

How do I run pipelined commands in paramiko? I'm doing it:

statement = 'grep thing file | grep thing2 | tail -1'
last_msg = conn.execute(statement)

and I get output only grep thing file.

+4
source share
1 answer

Because he grepdoesn’t know how to handle it |, be prepared for unpleasant shoots:

statement = """sh -c 'grep thing file | grep thing2 | tail -1'"""

This creates a shell on the other side and asks for its interpretation grep thing file | grep thing2 | tail -1 grep thing file | grep thing2 | tail -1 grep thing file | grep thing2 | tail -1. Single quotation marks are required because they sh -caccept only one argument.

Thus, the shell will create a channel for you by running all the commands. And you better be sure that the filename filedoes not contain spaces. If so, try it "file".

, . . sh -c script.sh.

+7

Source: https://habr.com/ru/post/1783368/


All Articles