3 ms·
Take a look at osh (Object SHell): https://github.com/geophile/osh https://github.com/geophile/osh It is a Python implementation of this idea: OS objects like
by geophile 8y ago
Take a look at osh (Object SHell): https://github.com/geophile/osh https://github.com/geophile/osh
It is a Python implementation of this idea: OS objects like files and processes are represented in Python. You construct pipelines as in UNIX, but passing Python objects instead of strings. E.g. to find the pids of /bin/bash commands:
osh ps ^ select 'p: p.commandline.startswith("/bin/bash")' ^ f 'p: p.pid' $
- osh: Runs the tool, interpreting the rest of the line as an osh command.
- ^: Piping syntax.
- ps: Generate a stream of process objects, (the currently running processes).
- select: Select those processes, p, whose commandline starts with /bin/bash.
- f: Apply the function to the input stream and write function output to the output stream, (so, basically "map"). The function computes the pid of an input process.
- $ Print each item received in the input stream.
Osh also does database access (query results -> python tuples) and remote access. E.g., to get a process listing of (pid, commandline) on every node in a cluster:
osh @clustername [ ps ^ f 'p: (p.pid, p.commandline)' ] $
- skykooler 8y agoThat said, that might not be the best example, because that same first command with Unix utilities is just: pgrep -f /bin/bash
- geophile 8y agoOK, how about this: osh timer 1 ^ \ f 't: (t, processes())' ^ \ expand 1 ^ f 't, p: (p.pid, int(t), p.commandline)' ^ sql "insert into process values(%s, %s, %s)" - timer 1: Generate a timestamp every second. - f 't: (t, processes())': Take the timestamp as input and generate a timestamp and sequence of Process objects. - expand 1: Expand the sequence of Processes, so that there is one per output tuple, e.g. (123, (p1, p2)) -> (123, p1), (123, p2). - f 't, p: (p.pid, int(t), p.commandline)': Take the timestamp and Process as input, and generate (pid, timestamp as int, command line) as output. - sql "insert into process values(%s, %s, %s)": Take the triples from the previous command and dump them into a table in a database.