ibrahim
ibrahim

Reputation: 3404

Is there any way to run a python script on remote machine without sending it?

I can run a shell script on remote machine with ssh. For example:

ssh -l foo 192.168.0.1 "`cat my_script.sh`"

Now I want to run a python script without sending .py file. Is there any way?

Upvotes: 10

Views: 6864

Answers (1)

Sean Dawson
Sean Dawson

Reputation: 5786

This will put the contents of my_script.py on your computer into an echo command that is performed on the remote computer and passed into python.

ssh -l foo 192.168.0.1 "echo '`cat my_script.py`' | python"

If you want to add command line args it should be as simple as putting them after the python command like so:

ssh -l foo 192.168.0.1 "echo '`cat my_script.py`' | python -testSwitch -arg 0"

Make sure that the command line args are inside the double quotes of the command you are sending to the remote host.

Upvotes: 11

Related Questions