CLI Overview
The AnyLog command prompt, running commands locally or across the network, executing scripts, and working with CLI variables.
The AnyLog CLI
Overview
Every AnyLog node provides a Command Line Interface (CLI) for executing commands, inspecting the node, managing services and metadata, running scripts, and interacting with peer nodes across the AnyLog network.
By default, commands entered at the CLI execute on the local node.
Using run client, the current node acts as a client to the AnyLog network and sends the command to one or more target nodes. Targets can be specified explicitly or resolved dynamically using the network metadata.
Note Most, but not all, AnyLog commands can be issued to a node through the REST interface. From the CLI, the
run clientcommand allows the current node to act as a client to the AnyLog network and issue a command to one or more target nodes.
The Command Prompt
The default CLI prompt is:
AL >
Users can assign a node name using set node name:
AL > set node name Operator_3
AL Operator_3 >
This is useful when working with multiple AnyLog nodes because the active node is immediately visible in the prompt.
See Set Node Name.
Pending Messages
A + in the prompt indicates that a message is waiting in the nodeβs echo queue:
AL +>
Retrieve queued messages using:
get echo queue
Clear the messages from the echo queue using:
reset echo queue
CLI Help
Use help to list available command families:
help
Search for commands associated with a command family:
help blockchain
Retrieve help for a specific command:
help blockchain get
Commands can also be searched by category:
help index
For example:
help index streaming
The built-in help provides command syntax, descriptions, examples, and links to the corresponding documentation.
Executing Commands Locally
Commands are executed on the current node unless run client is specified.
For example:
get processes
returns the processes running on the local node.
Other useful local commands include:
get connections
test node
get dictionary
blockchain get *
Basic CLI Operations
The CLI can operate on values maintained in the local AnyLog dictionary.
See Get and Set Reference for the complete dictionary and variable command reference.
Dictionary Variables
AnyLog maintains a local dictionary of key/value pairs that can be referenced from CLI commands and scripts.
Set a dictionary variable:
set company_name = AnyLog
Reference the value using !:
get !company_name
Use the value in another command:
blockchain get operator where company = !company_name
View the complete dictionary:
get dictionary
Search dictionary keys containing a string:
get dictionary _dir
This is useful when looking for configuration variables without knowing their exact key names.
For example, get dictionary _dir can locate values such as:
data_dir
watch_dir
prep_dir
error_dir
dbms_dir
Environment Variables
Environment variables are referenced using $.
For example:
get $HOME
Environment variables can also be created or changed directly from the AnyLog CLI:
set $ANYLOG_SITE = plant_1
Retrieve the value:
get $ANYLOG_SITE
Dictionary and environment variables can be used together in CLI commands and scripts.
Concatenating with +
In AnyLog, the + operator concatenates values.
Numeric variables are also treated as strings when used with +. Specifying .int or .float does not by itself cause arithmetic evaluation.
Given:
var1 = hello
var2 = world
var3 = 1
var4 = 3
Concatenating strings:
AL > !var1 + !var2
"helloworld"
AL > !var1 + " " + !var2
"hello world"
Casting Dictionary Values
CLI commands return values as strings. When a dictionary value needs to be used as another data type, it can be cast by adding a type suffix to the variable reference.
For example:
set port = 7848
set threads = 6
set enabled = true
The values can be cast when they are used:
!port.int
!threads.int
!enabled.bool
Common casts include:
.intβ integer.floatβ floating-point value.boolβ Boolean value.strβ string
For example:
set value1 = 10
set value2 = 5
result = python !value1.int + !value2.int
The value assigned to !result is (type: !result):
15
Without the python command, + performs string concatenation:
result = !value1.int + !value2.int
resulting in:
105
The cast determines how a dictionary value is represented when passed to a command or expression; it does not change the value stored in the dictionary.
The python Command
The python command evaluates an expression using a subset of Python operations.
Dictionary variables referenced in the expression are replaced with their assigned values.
Using:
var3 = 1
var4 = 3
integer addition:
AL > python !var3.int + !var4.int
4
floating-point addition:
AL > python !var3.float + !var4.float
4.0
or:
AL > python !var3.float + !var4.int
4.0
Other examples:
ip_port = python !ip + ':4028'
python 'D:/Node/AnyLog-Network/data/watch/'.rsplit('/',1)[0] + '.out'
new_dir = python !watch_dir.rsplit('/',1)[0] + '.out'
date_time = python "datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')"
Dictionary variables and environment variables can also be combined when constructing strings.
For example:
set $ANYLOG_PATH = /status
set host = 127.0.0.1
set port = 5432
address = !host + : + !port + $ANYLOG_PATH
The resulting value is:
127.0.0.1:5432/status
The incr Command
The incr command treats a variable as an integer and increments it by the specified value.
For example:
AL > k = 3
AL > incr !k 4
7
If no increment value is specified, the default increment is 1.
Running Commands as a Client to the Network
The run client command causes the current AnyLog node to act as a client to the AnyLog network.
By default, an AnyLog command is executed locally. Adding run client sends the command to one or more target nodes and returns the results to the node that issued the request.
Targets can be determined in several ways:
- explicitly by IP address and TCP port,
- from network metadata,
- from the database and table being accessed,
- or dynamically as part of a distributed SQL query.
Run on a Specific Node
Specify the AnyLog TCP IP address and port of the destination node:
run client 10.1.1.10:32148 get processes
Run on Multiple Nodes
Multiple destinations can be specified:
run client (10.1.1.10:32148, 10.1.1.12:32148) get processes
The request is sent to each node and their replies are returned to the client node.
Select Nodes Using Metadata
Targets can be discovered from AnyLog metadata.
For example, execute get status on all Operator nodes:
run client (blockchain get operator bring.ip_port) get status
The shorter metadata lookup syntax can also be used:
run client (operator bring.ip_port) get status
Filter Nodes by Metadata
For example, select Operators whose country attribute contains US:
run client (operator where [country] contains US bring.ip_port) get status
This allows the destination set to be resolved dynamically from the network metadata.
Select Nodes by Database and Table
A request can also be routed to Operators that support a specific logical database and table.
For example:
run client (dbms=litsanleandro, table=ping_sensor) get status
AnyLog uses the metadata to identify which Operators support the requested data.
The client therefore does not need to know the physical location of the data.
Accept Partial Results
For requests involving multiple nodes, subset=true allows AnyLog to return the available results even if some nodes do not reply.
For example:
run client (operator bring.ip_port, subset=true) get status
A TCP timeout can also be specified:
run client (operator bring.ip_port, subset=true, timeout=30) get status
In this example:
subset=trueallows a partial result.timeout=30limits the TCP wait time to 30 seconds.
Store Multi-Node Results
Results from a multi-node request can be assigned to a variable.
Use [] to organize the replies as a list:
nodes_stat[] = run client (blockchain get operator bring.ip_port, subset=true) get status
Use {} to organize the replies as a dictionary:
nodes_stat{} = run client (blockchain get operator bring.ip_port, subset=true) get status
Distributed SQL
Distributed SQL is another use of run client.
When the destination is empty:
run client () sql
AnyLog acts as a client to the network and uses the metadata to determine which Operators maintain the requested database and table.
For example:
run client () sql plant_data format=table and stat=select timestamp, temperature from sensors
AnyLog:
- Identifies the clusters that maintain the requested table.
- Identifies the relevant Operators.
- Distributes the SQL request.
- Executes the query against the physical data on the Operator nodes.
- Aggregates the replies.
- Returns a unified result.
A distributed SQL request can also specify options such as:
run client (subset=true, timeout=30) sql
See SQL Commands for distributed SQL syntax, output formats, query options, and examples.
Executing Commands at Startup
AnyLog commands can be executed automatically when the node starts.
Commands can be provided in several ways:
- As startup arguments.
- From
.alscripts executed withprocess. - Through deployment scripts.
- Through configuration policies.
Deployment scripts and configuration policies are commonly used to configure the services that define the role of a node in the network.
See Deployment Scripts.
Commands as Startup Arguments
Commands can be passed to anylog.py as quoted arguments.
Multiple commands are separated using and.
For example:
python3 anylog.py "get connections" and "get processes"
Execute a Startup Script
Commands are commonly organized in .al script files.
For example, assume anylog_setup.al contains:
run tcp server where internal_ip=!ip and internal_port=7848 and external_ip=!external_ip and external_port=7848 and bind=false and threads=6
run rest server where internal_ip=!ip and internal_port=7849 and external_ip=!external_ip and external_port=7849 and bind=false
The script can be executed when the node starts:
python3 anylog.py "process !local_scripts/anylog_setup.al" and "get connections"
Scripting
AnyLog scripts contain sequences of CLI commands and typically use the .al extension.
When an AnyLog node starts, deployment scripts and configuration policies commonly execute the commands that configure:
- node services,
- networking,
- databases,
- metadata synchronization,
- ingestion,
- high availability,
- and other node-specific behavior.
See Training & Tutorials and Deployment Scripts.
For Docker and Kubernetes-related commands, see Docker & K8s Commands.
process
Use process to execute a script on the main AnyLog processing thread:
process !local_scripts/my-scripts/my_script3.al
Commands in the script execute sequentially.
This is useful when later commands depend on earlier commands completing first.
thread
Use thread to execute a script on a separate thread:
thread !local_scripts/my-scripts/my_script3.al
A script started with thread runs independently from the main processing thread.
When multiple scripts are started using thread, they execute independently and are not guaranteed to complete in sequential order relative to one another.
Debugging Scripts
AnyLog provides two primary script debugging modes.
set debug on
set debug on prints each command and its execution result.
For example:
AL > process !local_scripts/my-scripts/script3.al
AL > [] [0002] set debug on --> Success
AL > [] [0003] run tcp server where internal_ip = !ip and internal_port = 7848 and external_ip = !external_ip and external_port = 7848 and bind = false and threads = 6 --> Success
AL > [] [0004] run rest server where internal_ip = !ip and internal_port = 7849 and external_ip = !external_ip and external_port = 7849 and bind = false --> Success
Disable debugging using:
set debug off
This can also be used inside a script to enable debugging only for a particular section.
set debug interactive
set debug interactive allows the user to control when each command in a script executes.
Interactive debugging cannot execute on the main thread, so the script must be started using thread.
For example:
AL > thread !local_scripts/my-scripts/script3.al
AL > [Thread-9 (_process_script)] [0001] set debug interactive --> Success
Run the next command:
AL > next
Example:
AL > [Thread-9 (_process_script)] [0003] run tcp server where internal_ip = !ip and internal_port = 7848 and external_ip = !external_ip and external_port = 7848 and bind = false and threads = 6 --> Success
The node can be inspected between commands:
get connections
Example:
Type External Address Internal Address Bind Address
---------|----------------|-------------------|-------------|
TCP |24.5.219.50:7848|192.168.86.29:7848|0.0.0.0:7848|
REST |Not declared |Not declared |Not declared |
Messaging|Not declared |Not declared |Not declared |
Execute the next script command:
next
Then inspect the connections again:
get connections
Example:
Type External Address Internal Address Bind Address
---------|----------------|-------------------|-------------|
TCP |24.5.219.50:7848|192.168.86.29:7848|0.0.0.0:7848|
REST |24.5.219.50:7849|192.168.86.29:7849|0.0.0.0:7849|
Messaging|Not declared |Not declared |Not declared |
Other commands can also be used while execution is paused:
get processes
get dictionary
blockchain get *
Continue executing the rest of the script without pausing:
continue
To stop using interactive debugging, remove:
set debug interactive
from the script or use set debug off where appropriate.
Script Control Flow
AnyLog scripts support conditional execution and control-flow operations including:
ifelsegoto- labels
- loops
waitend_script
For example:
if $setup_type == query then goto query_node
else goto operator_node
:query_node:
connect dbms test where type=sqlite
end_script
:operator_node:
connect dbms sensor_data where
type=psql and
user=anylog and
password=demo and
ip=127.0.0.1 and
port=5432
end_script
For complete scripting logic, labels, loops, conditions, and wait operations, see Conditional Execution & Control Flow.
Related CLI Documentation
The CLI documentation is divided into focused sections:
- Get & Set β dictionary variables, environment variables, node names, and configuration values.
- SQL Commands β local and distributed SQL queries.
- Conditional Execution & Control Flow β conditions, loops, labels,
goto, andwait. - Blockchain & Metadata β metadata policies and metadata management commands.
- Deployment Scripts β configuring node services using AnyLog scripts.
- Docker & K8s Commands β container deployment and troubleshooting.
A useful way to think about CLI execution is:
Local command
β
ββββΊ Execute on this node
run client ...
β
ββββΊ Act as a client to the AnyLog network
β
ββββΊ Explicit node
ββββΊ Multiple nodes
ββββΊ Metadata-selected nodes
ββββΊ Operators selected by the requested data