Requirements
-
nerves_hub_link2.5.0 or later. The device runs the script over its device connection, separate from the remote console, soremote_iexis not needed. - The device is online.
-
NervesHub 2.5.0 or later to show, create, update, and delete scripts through the API and
nh script, for shell scripts, and for script names that are unique per product. -
Permissions, from the built-in roles:
A custom role has each of these only if it is picked for the role. See Roles.
Languages
Each script has a language, which says what the device is expected to do with the text. NervesHub sends the text as written either way.
NervesHub checks an Elixir script for syntax errors when you save it. Shell scripts are saved as written.
A product can hold both kinds of device, and NervesHub offers every script on every device. An Elixir script sent to a Linux agent device comes back as a shell syntax error. Use the language and tags to tell the two sets apart.
Create a script
1
Open the scripts page
In your product, select Support scripts, then Add Support Script.
2
Fill in the script
Set a Name. Names are unique in a product, ignoring case. Optionally add Tags, which the scripts page searches along with names. Pick the Language, and enter the Script code.
3
Save
Select Save changes.
Run a script on a device
1
Open the device
In your product, select Devices, then the device. Stay on the Details tab.
2
Pick the script
In the Support scripts card, select a script. Each is listed with its language.
3
Run it
Select Run script. The output appears in the card. Clear removes it.
Use the CLI
Manage a product’s scripts withnh script (alias nh support-script):
create needs --name and a body from --text or --text-file (- reads standard input). --tags takes comma-separated tags. --language is elixir or shell, and defaults to Elixir on the server.
List the scripts a device can run, then run one by name or ID:
run-script prints the script’s output. --timeout sets how long the server waits for the device, such as --timeout 2m. The default is 30 seconds.
Use the API
Running a script answers with the output as plain text. Pass
timeout in milliseconds to wait longer than the default 30,000.
See API overview for authentication.
Limits
- Renaming or deleting a script breaks anything that runs it by name. Run by ID from automation if names may change.
- A script runs on one device per request. To run one across several devices, loop over them with the CLI or API.

