Skip to main content
A support script is text you save on a product and run on any of its devices. NervesHub sends the text to the device, the device runs it, and the output comes back to you. Use scripts for diagnostics you run often, and to let people run a vetted check without giving them a console.

Requirements

  • nerves_hub_link 2.5.0 or later. The device runs the script over its device connection, separate from the remote console, so remote_iex is 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.
Support scripts need nothing extra on the NervesHub instance.
A script runs with the same reach as the console: an Elixir script can call any function on the device. Every member with the View role can run every script on the product, so review what a script does before you save it.

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.
For an Elixir script, what the script prints and the value of its last expression both come back:
To change a script, select it on the Support scripts page. The page shows who last updated each script and when. Delete Script on the edit page removes it.

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.
Run script is disabled while the device is offline. If the device does not answer within 30 seconds, the card shows an error saying so.

Use the CLI

Manage a product’s scripts with nh 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.