RPYC makes it easy to implement remote method calls, while Plumbum can implement a shell-like encoding in Python:
The specific implementation code is as follows:
server.py
Import rpycfrom rpyc.utils.server import threadedserverfrom plumbum import localfrom plumbum.cmd import Shclass CalculatorService (RPYC. Service): "" " executes script based on path and script name :p Aram Path: path :p Aram Shn: Execute script Name" " " def exposed_ Execute (self, Path, SHN): exec=Sh[shn] with LOCAL.CWD (LOCAL.CWD/ path): Exec() returnif __name__ = = "__mai n__ ": Server = Threadedserver (Service=calculatorservice, port=12105) Server.start ()
client.py
Import rpycclass clientservice (RPYC. Service): def Exposed_foo (self): return "foo"conn = Rpyc.connect ("10.47.58.196", 12105) # Script path path= "/data/local/test" #脚本名shn = "echo.sh" #远程调用执行远程shell脚本x = conn.root.execute (path, SHN) Conn.close ()
Place the echo.sh script under the/data/local/test path, start the server.py remotely, and then execute client.py to remotely invoke the Execute echo.sh script.
RPYC + plumbum implements remote Call execution shell script