These recipes show common ways to use Level CLI from a terminal. Replace sample names such as web-01, Laptops, and Disk cleanup with resources from your Level account.
ℹ️ NOTE: Run lvl auth status before a recipe to confirm the active profile and Level organization. Prefer resource IDs when a name matches more than one record.
Sign in and verify the session
Start the browser-based sign-in:
lvl auth login
Confirm the active session:
lvl auth status
The login command prints a one-time code and verification URL. After you approve access in your browser, the CLI saves the session for the active profile.
List and filter devices
Search device names and return every matching page:
lvl device list --search web --limit all
Return the same results as JSON:
lvl device list --search web --limit all -o json
Use the built-in jq filter to select specific fields:
lvl device list --search web --limit all --jq '.list[] | {id, name, online}'--jq implies JSON output. String results print as plain text. Objects and other values print as compact JSON, one result per line.
ℹ️ NOTE: Paginated list commands return up to 100 records by default. Use --limit all only when you need the complete result set.
Export devices to CSV
Export devices in a group:
lvl device export --group Laptops > devices.csv
The export writes raw CSV to standard output. Redirect it to a file instead of adding -o json.
You can use the same pattern for alerts and automation runs:
lvl alert export --status resolved > resolved-alerts.csv
lvl run export --status error > failed-runs.csv
Run a read-only diagnostic on a Unix-like device
The following example checks filesystem usage on a Linux or macOS device:
lvl script run \ --device web-01 \ --command 'df -h' \ --shell bash \ --run-as current_user \ --wait \ -o json
This command creates an ad-hoc script run. --wait polls for completion and includes the step output in the result.
If you omit --wait, the CLI returns the discovered run IDs. Check a run later with:
lvl run get RUN_ID --wait -o json
⚠️ WARNING: Confirm the target operating system before running an ad-hoc command. Script creation and ad-hoc runs default to the SYSTEM run-as setting unless you specify another value.
Create and reuse a saved diagnostic script
If you already have a reviewed Bash script in os-info.sh, save it in Level:
lvl script create \ --name 'OS info' \ --file ./os-info.sh \ --shell bash \ --run-as current_user \ -o json
Run the saved script by name:
lvl script run 'OS info' --device web-01 --wait -o json
Override saved variable values for one run:
lvl script run 'Repair Chrome' --device web-01 --variable channel=stable --variable version=129 --wait -o json
--variable is available only when you run a saved script. Repeat --variable <name>=<value> for each override. You can identify a variable by name, ID, or {{reference}}. Variables you do not specify use their saved defaults. Each value is preserved exactly, including an empty value, commas, and additional = signs.
A saved script keeps its configured shell, timeout, and run-as setting. When you run a saved script by name or ID, do not add shell or run-as overrides.
Use a script ID when more than one script has the same name.
Preview an automation specification
Export an existing automation as YAML:
lvl automation spec 'Disk cleanup' > disk-cleanup.yaml
By default, references to other records use IDs, so they continue to identify the same records after a rename. To make supported resource references easier to read or edit, add --names:
lvl automation spec 'Disk cleanup' --names > disk-cleanup.yaml
The CLI uses a display name only when it resolves back to the same record. If the name is missing, ambiguous, or resolves to a different record, the ID remains in the export.
Not every ID is replaced. References to automation-local actions and variables can remain IDs. Use this recipe to review or update the existing automation, not as a complete cloning or cross-account migration recipe.
Preview how that specification would change the live automation:
lvl automation apply -f disk-cleanup.yaml --dry-run -o json
A dry run prints the planned changes without applying them.
After reviewing the file and the dry-run result, apply it with:
lvl automation apply -f disk-cleanup.yaml
⚠️ WARNING: Applying a specification reconciles the live automation with the file. A variables, triggers, or actions list included in the file is full state, so existing entries missing from that list can be deleted. Omit a whole list to leave it unchanged. Keep a current export, run --dry-run before every apply, and review any warnings.
Create an automation with references inside the same file
You can declare variables and actions in one specification, then reference them from other entries in that file. This is a separate create workflow from the existing-automation --names export recipe above.
Check the specification fields supported by your installed CLI:
lvl automation schema
lvl automation schema shell waitForOnline restart
lvl automation create --helpSave the following as
disk-check.yaml. This example is for Linux or macOS devices. It waits for the device to be online, runs the read-onlydf -hcommand, stores its output in a variable, and creates a Level alert if the command fails.name: Disk check reference recipe
description: Read disk usage and report command failures.
variables:
- name: disk_report
defaultValue: ""
triggers: []
actions:
- nickname: Wait until online
actionable:
waitForOnline: {}
- nickname: Check disk usage
onFailure: CONTINUE
outputVariable: disk_report
actionable:
shell:
command: df -h
shell: BASH
runAs: CURRENT_USER
timeout: 60
- nickname: Report failure
conditions:
- strategy:
stepStatus:
id: Check disk usage
values: [failed]
valueComparison: EQUAL
actionable:
createAlert:
name: Disk usage check failed
description: The disk usage command failed. Review the run output.
severity: WARNINGConfirm the organization with
lvl auth status, review the file, then create the automation:lvl automation create -f disk-check.yaml -o json
This command writes a new automation to Level. It does not run the actions on a device. The empty
triggerslist leaves this example without automatic triggers. Record the returned automation ID before making later updates.
onFailure: CONTINUE lets the run reach the final action after a failed disk check. Its stepStatus condition means the alert action runs only when Check disk usage failed.
Reference and validation rules
outputVariable: disk_reportrefers to the variable declared in this file. Use the exact case of the variable name.A
stepStatuscondition can identify an earlier action by its ID, unique nickname, or zero-based position. Here,"actions[1]"identifies Check disk usage and can replace its nickname in the condition. Use the exact nickname case. Action references must stay within this automation. AresolveAlertaction'ssourceIdalso refers to an earlier action.Each
actionableblock contains exactly one action type. Use enum values exactly as the schema shows them, such asBASH,CURRENT_USER, andCONTINUE.waitForOnline: {}has no timeout setting. An offline device waits at that step until it reconnects or the run is canceled.Names for resources outside the specification, such as saved scripts or tags, still need to resolve in the active organization. Keep this self-contained example separate from cloning or cross-account migration.
Replace an action type without moving the step
Export the automation you intend to edit. Replace
AUTOMATION_IDwith its actual ID, and keep an unchanged copy of the export:lvl automation spec AUTOMATION_ID > automation-update.yaml
Find the action entry you want to replace. Keep its
id, its position in theactionsarray, and every other action entry. Replace only that entry'sactionableblock. For example, this fragment changes the selected step into a 30-second pause:actionable:
delay:
duration: 30This is a fragment to insert into the exported action entry, not a complete apply file. Remove the old action-type key instead of keeping both types. Recheck output variables and downstream logic because the replacement performs a different operation.
Preview the full edited file:
lvl automation apply -f automation-update.yaml --dry-run -o json
Check for unexpected deletions, replacements, and warnings. Keeping the action in the same array position preserves its position in the automation. Step-status conditions that reference the replaced action are repointed to its replacement.
After reviewing the plan, apply the file:
lvl automation apply -f automation-update.yaml
The replacement has a new action ID. Export the automation again before your next edit so you use the current IDs.
Configure a user-scheduled Restart action
For a Restart action on Windows or macOS, use askForApproval with maxScheduleTime to let the signed-in user choose a restart time within a deadline. The following is an actionable fragment for an action entry in a complete specification:
actionable:
restart:
askForApproval: true
question: Save your work and choose a restart time within 4 hours.
frequency: 900
maxAttempts: null
maxTime: null
maxScheduleTime: 14400
frequency and maxScheduleTime are in seconds. This example sets a 15-minute reminder interval and a 4-hour scheduling window. Time asleep or powered off counts toward the scheduling deadline, but Level cannot restart a powered-off device at the selected time.
With askForApproval: true, provide a nonblank question and a positive frequency. Set at most one of maxAttempts, maxTime, and maxScheduleTime. Explicitly setting the unused limits to null clears any previous limits when you update an existing action. A supplied maxScheduleTime must be positive; null disables user scheduling.
WARNING: A Restart action can interrupt work. End-user prompting and scheduling are available on Windows and macOS. Linux restarts without an approval prompt. On Windows and macOS, if no user is signed in and no restart time is already chosen, the action restarts immediately. Review Restart Action before testing, and use the full-file dry-run and review workflow above before applying these settings.
Inspect monitor policies
List monitor policies:
lvl monitor policy list --limit all
Get one policy by ID or name:
lvl monitor policy get 'Server health' -o json
Export its specification:
lvl monitor policy spec 'Server health' > server-health.yaml
The default export uses IDs for references to other records, preserving the same targets after a rename. To use readable names for supported references instead, add --names:
lvl monitor policy spec 'Server health' --names > server-health.yaml
A name is used only if it resolves back to the same record. Missing or ambiguous names, or names that resolve to a different record, leave the ID unchanged, so a named export can still contain IDs.
Preview a specification before applying it:
lvl monitor policy apply -f server-health.yaml --dry-run -o json
Monitor policy apply also reconciles the live resource. Review its dry-run result before applying it.
Use group-qualified references
Device references can use an ID, hostname, name, nickname, or a group-qualified hostname:
lvl device get 'Servers/web-01'
Group-qualified references help when different device groups contain the same hostname. If a reference is still ambiguous, the CLI stops and lists the matches instead of choosing one.
Inspect exact flags and output shapes
Show normal command help:
lvl script run --help
Show the generated reference, including the JSON output shape:
lvl skill describe script run
Show every command under a group:
lvl skill describe update
The installed CLI is the source of truth for its current flags and output definitions.
Safety checklist
Before running a command that changes Level or a managed device:
Confirm the active organization with
lvl auth status.Confirm every target by ID, name, or group-qualified reference.
Review scripts and JSON or YAML specifications in full.
Check whether the command defaults to
SYSTEM, installs updates, reboots a device, or replaces a file.Use
--dry-runwhere available.Use
--yesonly after reviewing the complete set of selected resources.Check run history or update logs for asynchronous results.
Permanent delete commands require confirmation in an interactive terminal and require --yes in non-interactive execution. Some commands, including device restart and shutdown, request the action immediately without a confirmation prompt.
