Search code examples
pythonwindowremote-accessscapy

How to run a python script from local machine on a remote server and display the outputs live?


The only solution i found was this :

cat MyScript.py | ssh username@ip_addr python -

the problem with this is that it wont show the outputs of that script live, it waits until the program is finished and then it displays the output

I'm using scapy with in this script and sniff packets with it, and i have to run this on that remote server (and no, i cant copy it there or write it there)

so what is the solution? how can i view the outputs of a script live in my command line?

I'm using windows 10.

Important note: also i think ssh is using some sort of buffering, and sends the output after the amount of printed stuff gets more than buffer, since when the output is very large it does show part of it suddenly, i want the output of that function to come to my computer as soon as possible, not after reaching a buffer or something


Solution

  • You should first send the file to your remote machine using

    scp MyScript.py username@ip_addre:/path/to/script
    

    then SSH to your remote machine using

    ssh username@ip_addr
    

    ANd finally, you run you script normally

    python path/to/MyScript.py
    

    EDIT

    To execute your script directly without copying it to the remote machine, use this command:

    ssh user@ip_addr 'python -s' < script.py