RPYC + plumbum implements remote Call execution shell script

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.