0
stdout = session.exec_command('''find {} -name "{}*" -type f -exec stat -c "%n %y" {}<--**This is bash, not variable of format** + | awk "{ print $1" "$2 }" | grep -v word'''
.format(VARIABLE1, VARIABLE2))

I'm doing this code using paramiko 2.4 on Django 1.9.13, don't know how to deal with it, the error is:

KeyError at /get_xml/index/ ' print $1" "$2 '

UPDATED:

It doesn't crash right now, but doesn't returns anything, but if I do on bash, it's working, think there's missing something...

command = find {} -name '{}*.xml' -type f -exec stat -c '%n %y' {{}} + | awk '{{print $1, $2, $3}}' | grep -v 'word'

stdout = session.exec_command(command)

ANSWER

ssh.connect(hostname=VARIABLE1, username=VARIABLE2)
command = "find {} -name '{}*.xml' -type f -exec stat -c '%n %y' {{}} + | awk '{{print $1, $2, $3}}' | grep -v WHATIDONTWANTTO".format(VARIABLE3, WHATIWANTTOSEARCH)
_, stdout, _ = ssh.exec_command(command)
for item in stdout:
     #do whatever with items
     pass

finally it works, the last way was with session = ssh.get_transport().open_session() but it always retrieve 'Nonetype'

M. Mariscal
  • 1,226
  • 3
  • 17
  • 46

1 Answers1

2

As per documentation on .format, if you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.

So this -exec stat -c "%n %y" {} should be -exec stat -c "%n %y" {{}} and so on, if I understood your comment correctly.

Chillie
  • 1,356
  • 13
  • 16