The SHELL service provides a way to run commands and access files on a node. It is used by agents providing the REMOTE service to support remote execution of commands from other nodes.
Agents providing the SHELL service support execution of commands, and access to files on the node. While shell agents typically provide interactivity using a terminal/console, they also support messages for other agents to request execution of commands or access to files.
27.2. Script engines
The language in which the commands are written is not defined by the service, but depends on the shell agent. fjåge supports a pluggable mechanism for an
to use any
. Various script engines are available in fjåge and UnetStack, including the
Start the 2-node network and connect to node A:
> agentsForService org.arl.fjage.shell.Services.SHELL (1) [websh] > websh.send new ShellExecReq(cmd: 'file("foobar").text = "FOOBAR";') (2) websh >> AGREE > ls (3) foobar [6 bytes] README.md [759 bytes] > file("foobar").text (4) FOOBAR
We find that
We send a command to
The command was to create a
We read the contents of the
Next, let’s try the
messages to read, write and delete this file:
> websh.send new GetFileReq(filename: 'scripts/foobar') (1) websh >> INFORM: GetFileRsp > ntf.contents (2) [70, 79, 79, 66, 65, 82] > new String(ntf.contents) (3) FOOBAR > websh.send new PutFileReq(filename: 'scripts/foobar', contents: 'foooobaaaar') websh >> AGREE (4) > file('foobar').text (5) foooobaaaar > websh.send new PutFileReq(filename: 'scripts/foobar', contents: null) websh >> AGREE (6) > ls README.md [759 bytes] > websh.send new GetFileReq(filename: 'scripts') (7) websh >> INFORM: GetFileRsp > new String(ntf.contents) README.md 759 1568297372000 (8)
|2||The file contents are read back as a list of bytes.|
We convert the list of bytes to a String to get our
We send a
|5||We verify that the file contents were indeed changed, as requested.|
Asking for the contents of a directory using
The listing consists of all files in the directory, one file per line. Each line has a filename, file size and file modificiation timestamp (epoch time). If a file is a directory, the filename is suffixed by a
We interacted with the SHELL service provider using a shell! That’s not very useful in practice, but served to show you how these messages work. Typically, these messages are sent by other agents that wish to get the shell to run commands and access files for them (e.g.
). The agents may be running remotely in a fjåge slave container or on a gateway (via the UnetSocket API), where they may not have direct access to the filesystem of the node.
|<<< [Scheduler]||[Developing your own agents] >>>|