REXEC(3)
โจ REXEC โจ (the rexec man page, section 3, rexec 1.2 bestie ๐)
๐ซ NAME ๐ซ
nfstest.rexec โ the Remote procedure module ๐ซถ
๐ธ DESCRIPTION ๐ธ
Okay so picture this: you've got a whole lil toolbox for running a huge range of commands, statements, expressions or functions over on a remote host. How? By running a server process on that remote host that just... serves your requests without disconnecting. Iconic behavior honestly. โจ
The way that matters is: it lets you do a whole sequence of operations remotely and not lose state. Like, you could open a file remotely, go do a bunch of other stuff, and then write to that same still-open file without opening it all over again. No re-opening, no drama. ๐
The remote server can also run as a different user by using the sudo option and sending seteuid. And it can run locally too โ using fork when it's running as the same user, or using the shell when the sudo option is in play. Versatile queen. ๐
โ ๏ธ Real talk though: to use this module, your user id has to be able to ssh to the remote host without needing a password. No password, no vibes. Periodt.
๐ CLASSES ๐
๐ class RemoteServer(builtins.object)
โจ Methods defined here:
__del__(self)โ the Destructor ๐ชฆ__init__(self, port, logfile=None)โ Remote procedure serverlog(self, msg)โ write message to log file ๐start(self)
๐ฆ class Rexec(baseobj.BaseObj)
Rexec object ๐ซง
Rexec() -> New remote procedure object
Arguments:
servernameโ name or IP address of remote serverlogfileโ name of logfile to create on remote serversudoโ run remote server as root
Usage:
from nfstest.rexec import Rexec
# Function to be defined at remote host
def add_one(n):
return n + 1
# Function to be defined at remote host
def get_time(delay=0):
time.sleep(delay)
return time.time()
# Create remote procedure object
x = Rexec("192.168.0.85")
# Define function at remote host
x.rcode(add_one)
# Evaluate the expression calling add_one()
out = x.reval("add_one(67)")
# Run the function with the given argument
out = x.run("add_one", 7)
# Run built-in functions
import time
out = x.run(time.time)
# Import libraries and symbols
x.rimport("time", ["sleep"])
x.run("sleep", 2)
# Define function at remote host -- since function uses the
# time module, this module must be first imported
x.rimport("time")
x.rcode(get_time)
# Evaluate the expression calling get_time()
out = x.reval("get_time()")
# Run the function with the given argument
out = x.run("get_time", 10)
# Open file on remote host
fd = x.run(os.open, "/tmp/testfile", os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
count = x.run(os.write, fd, "hello there
")
x.run(os.close, fd)
# Use of positional arguments
out = x.run("get_time", 2)
# Use of named arguments
out = x.run("get_time", delay=2)
# Use of NOWAIT option for long running functions so other things
# can be done while waiting
x.run("get_time", 2, NOWAIT=True)
while True:
# Poll every 0.1 secs to see if function has finished
if x.poll(0.1):
# Get results
out = x.results()
break
# Create remote procedure object as a different user
# First, run the remote server as root
x = Rexec("192.168.0.85", sudo=True)
# Then set the effective user id
x.run(os.seteuid, 1000)
๐ Methods defined here:
__del__(self)โ Destructor ๐ชฆ__init__(self, servername=None, logfile=None, sudo=False, timeout=30.0)โ Constructor
Initialize object's private data. ๐พ
servernameโ host name or IP address of host where remote server will run [Default:None(run locally)]logfileโ pathname of log file to be created on remote host [Default:None]sudoโ run remote procedure server as root [Default:False]timeoutโ timeout for synchronous calls [Default:30.0]
close(self)โ close connection to remote server ๐poll(self, timeout=0)โ return whether there is any data available to be readtimeoutโ maximum time in seconds to block, if timeout isNonethen an infinite timeout is used โณ
rcode(self, code)โ define function on remote serverresults(self, xid=None)โ return pending resultsreval(self, expr)โ evaluate expression on remote server ๐งฎrexec(self, expr)โ execute statement on remote serverrimport(self, module, symbols=[])โ import module on remote server ๐ฆmoduleโ module to import in the remote serversymbolsโ if given, import only these symbols from the module
run(self, *kwts, **kwds)โ run function on remote server ๐โ๏ธ
The first positional argument is the function to be executed. All other positional arguments and any named arguments are treated as arguments to the function.
wait(self, objlist=None, timeout=0)โ return a list ofRexecobjects where data is available to be readobjlistโ list ofRexecobjects to poll, if not given use current objecttimeoutโ maximum time in seconds to block, if timeout isNonethen an infinite timeout is used โณ
๐ SEE ALSO ๐
๐ BUGS ๐
No known bugs. (Not a single one, bestie โ we ate and left no crumbs. ๐ฅ)
๐ AUTHOR ๐
Jorge Mora (mora@netapp.com)
And that's the whole page, fr fr ๐ซถ This was NFStest 3.2, dated 21 March 2023 โ go forth and remote-procedure slay ๐ โจ
๐ฆ where this page comes from
- debian trixie: nfstest 3.2-3
- fedora 43: NFStest 3.2-14.fc43 ยท GPL-2.0-or-later
- fedora 44: NFStest 3.2-16.fc44 ยท GPL-2.0-or-later
- ubuntu noble: nfstest 3.2-2
- ubuntu questing: nfstest 3.2-3
- ubuntu resolute: nfstest 3.2-3build1
- ubuntu stonking: nfstest 3.2-5
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms