python: execute function on remote file through ssh.

 

 

os.system(‘ssh USER@REMOTE_IP python3 /PATH/TO/REMOTE/FILE.py ARGUMENT’)

 

note than the argument i’m using is 1 (as a random character, you can use whatever you like)

 

then on the file you “fish” the argument and use an if statement (sorry for the lack of tabs on the code below)

 

try:
import sys

argument = sys.argv[1]

print(‘the argument is: ‘ + argument)

if argument == ‘1’:
print(‘will execute the leads cleanup’)
delete_by_title_leads(‘1’)
except:
print(‘no argument’)

 

 

 

Leave a Reply

Your email address will not be published.