0

I try to check file existence on a remote server. Everything works fine for me, except that I want to pass the file path as a variable.

Here is what I do _,stdout,_=ssh.exec_command("[ -f d:/tryssh/1.txt ] && echo OK")

and I need this d:/tryssh/1.txt to be a variable that I specify in the python script to be used later in the bash, something like this

          `_,stdout,_=ssh.exec_command("[ -f $filePath ] && echo OK")`
AhmedWas
  • 1,205
  • 3
  • 23
  • 38

1 Answers1

1

As your command is a string, use it as a string:

file_path = "d:/tryssh/1.txt"
command = "[ -f %s ] && echo OK" % file_path
_,stdout,_=ssh.exec_command(command)
fgoettel
  • 351
  • 2
  • 6
  • Unfortunately, that didn't work. Simply because `%s` is not identified in the bash syntax, only in python syntax. But thanks anyway – AhmedWas May 11 '15 at 15:10