Issue
I have a python script on my local machine, which just prints "hello world". I want to run this script on a remote machine via ssh, using Expect. I am using Expect to automate entering the password. Entering the following commands to the command line runs the local script on the remote machine, however they require the user to enter the password:
ssh [email protected] python < hello .py
or
cat hello.py | ssh [email protected] python -
The following .exp script automates entering the password, but runs a script which is already on the remote machine.
#!/usr/bin/expect
spawn ssh [email protected] python < hello.py
set pass "1"
expect {
password: { send "$pass\r"; exp_continue }
}
If hello.py file is not found on the remote machine, I get the following message: "bash: hello.py: No such file or directory". Can anyone help me please? Thanks in advance.
Edit: I do not want to first copy the script to the remote machine and then execute it. I tried and it works, but simply I do not want to run it this way.
Solution
<
is not special in Expect/Tcl. spawn ssh [email protected] python < hello.py
is like you manually run ssh [email protected] "python < hello.py"
where the <
is interpreted on the remote side.
You can write like this:
spawn bash -c "ssh [email protected] python < hello.py"
or
spawn bash -c "cat hello.py | ssh [email protected] python"
Answered By - pynexj