run python on another machine

-1

Is it possible to run a python script on another machine on the network?

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

    
asked by anonymous 10.07.2018 / 01:13

1 answer

0

The most straightforward way to do this is simply to use ssh - you leave the machine where you want to run the preconfigured command, and accept connection by cryptographic keys from an identity where you are going to connect, and pass the command to to be executed (python followed by the script name), right on the ssh command line.

Everything that does not work on windows!

So instead of installing things to upload and reconfigure 30 years of Unix / Linux history inside Windows - which is possible, but it's no longer the easiest way, it's best to have a Python system that somehow receives the command you want and executes it - 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 port of the machine, directly or indirectly, performing what you want.

One of the ways is to use celery - celery is most often used to perform time-consuming tasks as part of web systems - without anyone using it the web system has to wait for the task. But this is possible because it makes it extremely simple 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 for performing specific tasks on specific machines however - and maybe it will take a lot of work to set up the celery for this. (Type "I need someone to figure this out", and one of the celery workers, on any machine that is setup 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 leave a program running 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 file using Flask with views to call each task you want to run - there, from remote computers, you just need to access the specific urls. This way does not require you to have a Python program on the client machine, from where you will have to execute the commands - 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 to "hello world", and enter, before the line return "hello world!" , a call to the function that does what you want to perform. Ready.

    
11.07.2018 / 17:19