# sa-cli — SA1 ops CLI :id=top

------

> _Doc Ver:_ 1.0  
_App Ver:_ 2.6.6.53  
_Date:_ 09/10/2026

------

`sa-cli` talks to the device **only through sa-web HTTP**. It is not a TUI, listens on no port, and does not replace the browser. Binary: `/var/sa/bin/sa-cli` (not supervised).

**Not** SA2 `sa_tui`. Do not open TCP 7090.

Hub: [Ops tools](ops.md). HTTP JSON: [API §8](api.md). Checkup: [sa-doctor](sa-doctor.md). MCP: [sa-mcp](sa-mcp.md). Full SCPI: [API](api.md).

The binary `--help` text is **Chinese**. English below matches it. On the device:

```bash
sa-cli --help
sa-cli help
sa-cli help reload
sa-cli --version
```

Unknown commands print full usage to stderr and exit 3. Flags may appear **before or after** the command (`sa-cli reload --yes` equals `sa-cli --yes reload`).

------

## 1. CLI help (same coverage as `sa-cli --help`) :id=cli

```
sa-cli 2.6.6.29 — SA1 ops CLI (not a TUI, not SA2 sa_tui)

HTTP to sa-web only. Do not open TCP 7090. Not a full terminal UI.

Usage:
  sa-cli [flags] <command> [args]
  sa-cli help
  sa-cli help <command>
  sa-cli --help
  sa-cli --version

Flags (before or after the command, e.g. sa-cli reload --yes, sa-cli frq --demod):
  --url URL            sa-web: host, host:port, or http://host[:port]
                       If omitted, probe 127.0.0.1 80 → 8080 → 81 (3s each,
                       independent of --timeout). An explicit port skips the probe.
                       Env: SA1_URL
  --user NAME          Web user (default admin). Env: SA1_USER
  --password PASS      Web password. Prefer SA1_PASSWORD
  --timeout DURATION   HTTP timeout after login (default 12s)
  --write              allow non-query SCPI (required for sa-cli scpi writes)
  --yes                confirm destructive actions (reload / time / upgrade)
  --demod              frq only: ask :DATA:FRQ? (~20s window); default :SYS:FRQ?
  -h, --help           this text
  -v, --version        print version and exit

Environment: SA1_URL  SA1_USER  SA1_PASSWORD

Commands:

  info                 public GET /api/info (no login)
                       app name, IDN, dotted version

  health | status      GET /api/ops/health after login
                       JSON: processes, mutex, 7090, disk, init, version match

  me                   GET /api/me after login
                       name / role / can_operate / can_manage_users

  scpi <cmd>           whitelist SCPI via tcpclient.php (sa-web → local 7090)
                       reads (contains ? or prefixes :JSON:GET / :JOSN:GET /
                       :FILE:GET / :FBG:GET / :FBG:CFG / :VS:GET / :VS:CFG) allowed
                       writes need --write. Gateway still denies *CHS! / *CHW! /
                       :CMD? shell / :SYS:HOOK / shutdown-upgrade family
                       e.g. sa-cli scpi '*IDN?'
                            sa-cli scpi ':DATA:PVJ?'
                            sa-cli --write scpi ':SYS:RELOAD'
                       Precise-wl verify with :DATA:PVJ?, not :DATA:PV?
                       After editing precise_wl.json: sa-cli reload --yes

  sensors              :FBG:CFG? sensor register

  frq                  default :SYS:FRQ? (hardware rate, immediate)
                       --demod → :DATA:FRQ? (demod throughput, ~20s; timeout ≥ 25s)

  save                 getjson.php?name=data_save.json

  reload --yes         POST /api/ops/action {"op":"reload","confirm":true}
                       :SYS:RELOAD; sa-di rereads conf. Operator role.

  time <value> --yes   POST /api/ops/action op=time
                       value is Unix seconds or sa-di stamp; one token; no space or ;|&
                       Operator role.

  upgrade --yes        POST /api/ops/action op=upgrade
                       background sa1-upgrader upgrade -y; no reboot by default
                       Operator role. Not cspkg.

  help [command]       this text, or a short command blurb
  version              same as --version

Roles (sa-web RBAC; CLI only adds --yes / --write):
  superuser, administrator (legacy operate / admin)
                       may reload / time / upgrade and --write SCPI
  user, guest          read info / health / me / query SCPI / sensors / frq / save
                       writes → HTTP 403
  missing --password   exit 3 except info
  factory password     often temppwd (change on site; do not commit)

Login: POST /api/auth/login JSON {"username","password"} (also accepts name)
       returns token; then Authorization: Bearer or Cookie sa_web_session

Discover: without a port, 80 → 8080 → 81. --timeout applies after login (12s).
          --demod raises timeout to 25s if it was lower.

time value: one token (Unix seconds or sa-di stamp). No space, tab, newline, ; & |
upgrade: /usr/local/bin/sa1-upgrader upgrade -y, log
         /home/debian/sa1/persist/log/sa1-upgrader.log ; no reboot; not cspkg.

Exit codes:
  0  success
  1  HTTP / login / gateway failure (including 403)
  3  usage, missing password, write without --yes/--write

Binary: /var/sa/bin/sa-cli (in the package, not supervised).
After install/upgrade /usr/local/bin/sa-cli points at it.
Handbook: web/help/zh-cn/sa-cli.md    web/help/sa-cli.md
Hub: web/help/zh-cn/ops.md    HTTP: web/help/zh-cn/api.md

Not: SA2 sa_tui; not a browser replacement; no listen port; no LAN 7090.
```

`sa-cli help <command>` blurbs: info, health/status, me, scpi, sensors, frq, save, reload, time, upgrade, help, version — same as the table in the Chinese page.

------

## 2. HTTP per command :id=http

| Command | Method | Path | Auth | Extra |
|---------|--------|------|------|-------|
| info | GET | `/api/info` | no | `name`, `idn`, `version`, optional `version_raw` |
| health / status | GET | `/api/ops/health` | yes | full document — [API §8](api.md) |
| me | GET | `/api/me` | yes | `name` `role` `display_name` `enabled` `can_operate` `can_manage_users` |
| scpi | GET | `/tcpclient.php?cmd=` | yes | writes need `--write`; gateway whitelist |
| sensors | GET | `/tcpclient.php?cmd=:FBG:CFG?` | yes | |
| frq | GET | `:SYS:FRQ?` or `:DATA:FRQ?` | yes | `--demod` sets client timeout ≥ 25s |
| save | GET | `/getjson.php?name=data_save.json` | yes | raw JSON to stdout |
| reload | POST | `/api/ops/action` `{"op":"reload","confirm":true}` | operator | `--yes` or exit 3 with no request |
| time | POST | `op=time` + `value` | operator | `--yes`; value must not contain space `;` `&` `\|` |
| upgrade | POST | `op=upgrade` | operator | `--yes`. Background; **no reboot**. Not cspkg. |

Login: `POST /api/auth/login` (also `/api/login`) JSON `username`/`password` (or `name`). Returns `token`. Client sends Cookie `sa_web_session` and `Authorization: Bearer`.

------

## 3. Read vs write SCPI :id=scpi

Treated as read if the command contains `?` or starts with (case-insensitive): `:JSON:GET`, `:JOSN:GET` (legacy spelling), `:FILE:GET`, `:FBG:GET`, `:FBG:CFG`, `:VS:GET`, `:VS:CFG`. Everything else needs `--write` or the process exits 3 without sending. The gateway still 403s `*CHS!` / `*CHW!`, `:CMD?` shell, `:SYS:HOOK`, shutdown/upgrade family. Switch spectrum with `:DATA:ODT OS` / `:DATA:ODT WAV`. Full list: [API](api.md).

`:DAQ:FRQ?` / `:DATA:FRQ?` need a ~20 s window. Default `frq` is immediate `:SYS:FRQ?`. Demod throughput: `sa-cli frq --demod`.

------

## 4. Examples :id=ex

```bash
export SA1_URL=http://127.0.0.1 SA1_USER=admin SA1_PASSWORD=…
sa-cli info
sa-cli me
sa-cli health
sa-cli sensors
sa-cli frq
sa-cli frq --demod
sa-cli save
sa-cli scpi '*IDN?'
sa-cli scpi '*VER?'
sa-cli scpi ':DATA:PVJ?'
sa-cli --write scpi ':SYS:RELOAD'
sa-cli reload --yes
sa-cli time 1710000000 --yes
sa-cli --url http://192.168.3.6:8080 upgrade --yes
```

Upgrade log: `/home/debian/sa1/persist/log/sa1-upgrader.log`. Install/upgrade clients: [cspkg](cspkg.md) / [Upgrade](upgrade.md).

Precise wavelength: verify with `sa-cli scpi ':DATA:PVJ?'`, not `:DATA:PV?`. After editing `WLCAL_ENABLE` in `/var/sa/conf/precise_wl.json`, `sa-cli reload --yes`. Vs wavemeter, scan bias ~+22 pm falls to ~0.5 pm. Full text: [Precise wavelength](precise_wl.md) “Command line”.

------

### [Top](#top)
