4

I have a basic (server1) Django development web server and another server (server2) which has a python script that does some scientific calculations. Assume that the server1 has necessary authentication in place to run the script on server2. All I want to do is, click a button on the django website which would run the python script sitting on server2.

Ideas that I have so far are,

  • use some kind of SSH library to run the script and get response
  • have a REST API setup on server2 to run the script

Not sure if above ideas would work, please suggest your insight into this and if possible a simple example would be appreciated.

More info: Server1 and Server2 has to be 2 separate servers, server1 is a webserver, while server2 can be any linux virtual machine. Also, the response from server2 has to be sent back to server1.

3
  • Do you absolutely need that server1 get the server2 script response? Commented Nov 18, 2014 at 23:53
  • @David W. Yes, getting back the response is essential in my case. Commented Nov 19, 2014 at 6:38
  • 1
    @DavidW. If I don't need a response in return: what's your suggestion/answer? Commented Jan 14, 2015 at 9:27

2 Answers 2

1

After reading through and trying out various forum suggestions and spending solid time in Google, I've settled down with paramiko. It does exactly what I wanted and works like a charm for now.

On click of a button on my website, running on server1, I make a request to run a python script. The python script uses paramiko to make SSH connections to server2, runs the necessary command and writes a response to a plain/text file. This plain/text file is rendered back to the request through django form as a response.

This looks a little dirty now and there are more things to look into like, what happens if the command took very long time to execute or it erred out for some reason. I haven't spent time in figuring out answers for all those questions, but eventually will.

Sign up to request clarification or add additional context in comments.

Comments

0

There is no reason why server one cannot execute something like selenium or phantomjs on itself to navigate to your website on server2 and click a button on server 2 which then uses something like python's subprocess module to execute a program from server 2.

1 Comment

Server2 is not a website, but a Virtual Machine which has several scientific data processing scripts. All that the server1 knows is the location of the script on server2 and the command to execute it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.