Scripts and exit codes
The same commands run without a prompt:
Shell
nnc router1 -c 'get-config running' > running.xml
nnc router1 -c 'modules' -c 'device cli --command "show version"'
nnc router1 --script checks.nnc
nnc --script session.nnc # the script does its own connect
echo 'value @systemName' | nnc router1- Given a target, nnc connects first.
--read-only,--framedand--rawafter the target apply to that connection. -ccan be repeated.--scriptcan be shortened to-s;--script -reads standard input.- Results go to standard output. Errors, warnings, notifications and traces go to standard error. Errors name the script and line:
checks.nnc:3: …. - A script stops at its first failed command. Add
set on-error continueto run the rest; the exit code is then that of the first failure. - Colour and paging are off when the output isn't a terminal.
Exit codes
| Code | Meaning |
|---|---|
| 0 | every command succeeded |
| 1 | the device returned an <rpc-error> |
| 2 | a command couldn't be parsed or was used wrongly |
| 3 | connection, authentication or host-key failure |
| 4 | refused by the read-only guard |
| 5 | a timeout, a protocol error, or the session closed unexpectedly |
| 130 | cancelled with Ctrl-C |
Example: a nightly check
Shell
#!/bin/sh
# checks.nnc: fails the job if the device or its profile misbehaves
cat > checks.nnc <<'EOF'
capabilities
value @systemName
read /ietf-interfaces:interfaces --state > interfaces.xml
EOF
nnc router1 --read-only --script checks.nnc