I am new to this and need some advice on resolving my problem. I have a python script on a remote server. I want to execute that script from my local system and then transfer the result file generated on the remote server to my local system.
So, I would be grateful if someone can help me with a script or single command that can do this.
I tried a script but when I am in the remote server via SSH, the second line to execute the python script does not work. I also tried using nohup but still, it is not working
Below are the steps that need to be followed
- ssh
- python script.py
- Then 'exit' from ssh
- scp <output_file>
1 Answer
You can do this with
ssh user@server "python script.py"
scp user@server:/remote/file.txt /local/directoryThis executes the script on the remote machine, providing you have the proper ip address and filepaths, and will then copy the file from the remote machine to yours.
You could also execute the script using a cron job on the remote machine if you would like to look into it
EDIT: There is no need to actually exit ssh, becuase this ssh command executes the command, but does not establish a running shell, you can test this by running ssh localhost ls