run python on another machine

Asked

Viewed 679 times

-1

Staff it is possible to run a python script on another network machine?

Example: I use the dev01 machine and I need to execute a script for collection and data on the BD03 machine both machines have python installed and all right, I intend to do this because my LAB has 1 vm database and 1 vm dev (ai wanted to run some script "remotely" of a Linux parea a Windows and vise and versa

  • Cannot connect via SSH?

  • So the problem is that it is a Windows Server machine and sometimes it is a debian bags? I thought I’d do something kind of automated where from my machine I can collect the information without having to access... As if it were a "execute=192.168.0.18" (run on the machine x understood?)

  • You can use Ansible for such.

1 answer

0

The most "Straightforward" way to do this is simply to use ssh - you leave the machine where you want to execute the preconfigured command, and accepting connection by cryptographic keys of an identity from where you will connect, and pass the command to be executed (python followed by script name), right at the ssh command line.

Everything that doesn’t work in windows!

So instead of installing things to climb and reconfigure 30 years of Unix/Linux history inside Windows - which is possible, but no longer the easiest way, the best is to have a Python system that somehow gets the command you want and run itthe - or directly, calling functions within itself, or as external processes.

There are some approaches to this - in common in all of them is that you will have a Python process, listening on some machine door, directly or indirectly, running what you want.

One of the ways is using Celery - Celery is mostly used to perform time-consuming tasks as part of web systems - without anyone using the web system having to wait for the task. But this is possible because it makes it extremely simple for you to call a function almost as if it were a normal Python call, and it runs on another computer on the network. It is more used for parallel processing than to perform specific tasks on specific machines however - and it may take a lot of work to set up Celery for that. (Like "I need someone to calculate this," and one of Celery’s Workers, on any machine that is configured goes there and performs is the most normal use).

Another way is to use xmlrpc or jsonrpc - see the documents in the standard Python library even on xmlrpc - it is simple to let a program run with a function that will be called remotely from another Python program. Remember, in Python 3 to always pass byte-strings as parameter.

Another way is to make a cameo using Flask with views to call each task you want to perform - then, from the remote computers, you just need to access the specific urls. This form does not require you to have a Python program on the client machine, from which you will have the commands executed - and it’s actually quite simple: see what function does "everything you need" on the target computer, go in a Flask tutorial and make up the "hello world", and, insert, before the line return "hello world!", a call to the function that does what you want to perform. Ready.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.