I am trying to use ssh
command in the subprocess.call
function of Python 2.6.8
on Unix environment to call a remote script, and I need to provide a string parameter (with whitespaces) to the remote script. However, the string parameter is not being interpreted correctly when I run the python script.
Here is my python script :-
#!/usr/bin/python
from subprocess import call
ret=call(['ssh','user@host','\"/remote/path/to/script/test.sh','\'Hi','There\'\"'])
print ret
ret2=call(['ssh','user@host','/remote/path/to/script/test.sh','Hello'])
print ret2
I am getting following output with error and returncode 127
for the ssh command with "whitespace string", and the second ssh command is running fine with returncode 0
:-
bash: /remote/path/to/script/test.sh 'Hi There': No such file or directory
127
Hello
0
The same shell command executes successfully when I run it on shell command line terminal :-
Command:
ssh user@host "/remote/path/to/script/test.sh 'Hi There'";echo $?
Output:
Hi There
0
Here is the content of remote script /remote/path/to/script/test.sh
(if it helps) :-
#!/usr/bin/ksh
echo $1;