Reputation: 19243
I'm using Linux
to log into a server using ssh
. Once I'm logged in, I would like to execute a local Python
script which uses netcat
to run some program on the remote machine (it is therefore required to be logged in to access it).
Locally I can type ./script.py
on bash
to run the script however if I do it while being connected to the remote server that doesn't work. This is due to the fact that the terminal now is in a directory on the remote machine and no longer in a local one.
So how do I execute my local script against the remote machine while being logged in without copying it over first?
Upvotes: 1
Views: 96
Reputation: 51
You can do it easily using pipes:
my sample program to test: (py.py)
import socket
print socket.gethostname()
running remotely:
ssh remoteserver "python" < py.py
the output was:
remoteserver name
If your user's path not contains python, you must use full path
ssh remoteserver "/usr/bin/python" < py.py
in my environment.
Upvotes: 2