Run script on remote server from Django webserver

I have a basic (server1) Django development web server and another server (server2) that has a python script that does some scientific calculations. Let's assume server1 has the required authentication to run the script on server2. All I want to do is click a button on the django website that will run the python script while sitting on the server2.

The ideas that I still have

  • use some ssh library to run your script and get the response
  • you have a REST API setup on server2 to run your script

Not sure if the ideas will work, please offer your understanding of this and a simple example would be appreciated if possible.

Additional information: Server1 and Server2 must be 2 separate servers, server1 is the web server and server2 is any Linux virtual machine. Also, the response from server2 must be sent back to server1.

+3


source to share


2 answers


After reading and trying out various forum suggestions and spending a lot of time on Google, I settled in with paramiko. It does what I wanted and now it works like a charm.

When a button is clicked on my website running on server1, I make a request to run a python script. The Python script uses paramiko to SSH into server2, runs the required command and writes a response to a plain / text file. This plain / text file is returned to the request via the django form as a response.



It looks a little messy now, and there are more things to see how that happens if the command took a very long time to complete, or it was wrong for some reason. I haven't taken the time to figure out the answers to all of these questions, but eventually I will.

+1


source


There is no reason the server can't execute something like selenium or phantomjs on itself to go to your site on server2 and click a button on server2, which then uses something like a python subprocess module to execute the program from server2.



0


source







All Articles