mqtt-exec(1)
π mqtt-exec β the manual page, but make it make sense
okay so bestie, welcome to mqtt-exec(1) from the General Commands Manual β¨ this is genuinely one of my fave little tools and i'm gonna walk you through it like we're texting at 2am π«Ά
πΈ NAME πΈ
mqtt-exec β execute a command for MQTT messages. that's it. that's the whole vibe. a message comes in, a command goes out. iconic behavior fr π
β¨ SYNOPSIS β¨
mqtt-exec [options...] -t topic... -- command [args...]
like, options first, at least one -t topic, then the sacred -- divider, then your command and its args. the -- is NOT optional bestie, respect the boundary π
π¦ DESCRIPTION π¦
so what does it actually do? mqtt-exec connects to an MQTT broker, subscribes to one or more topics, and executes a command when messages are received. that's the whole loop. no cap. π₯
By default, the message payload is passed as the last argument to the configured command. When -v is used, the topic is passed as the second-to-last argument and the payload is passed as the last argument. so -v just slides the topic in right before the payload, cute π
Empty payloads are ignored unless -v is enabled. so if nothing's in the message, nothing happens β unless you're in verbose mode, in which case the empty payload still gets its little moment π«Ά
After each successful connection, mqtt-exec can optionally publish an "up" status message before waiting for subscribed messages. lowkey a little "hey i'm here" text to the group chat π
When --status-down-payload is configured, mqtt-exec publishes that message on clean shutdown. Unexpected termination is still handled separately through the MQTT will configured with --will- options. so like, the polite goodbye is one thing, and the dramatic exit is a whole separate mechanism, and they do NOT overlap π«
okay this next bit matters: the clean-shutdown status publish is best effort. mqtt-exec attempts to flush it before disconnecting, but does not wait for a full QoS 1 or QoS 2 delivery handshake before exiting. so it tries its best and then leaves. main character energy but with a caveat π
π OPTIONS π
here's the whole menu, no skipping, i would never π
-c,--disable-clean-sessionβ Disable the MQTT clean session flag.-d,--debugβ Enable debug output from the MQTT client library. it gets chatty, you've been warned π-h,--hosthost β Connect to host. The default islocalhost.-i,--idid β Set the client identifier.-k,--keepaliveseconds β Set the MQTT keepalive interval. The default is60.-p,--portport β Connect to TCP port. The default is1883.-P,--passwordpassword β Set the password used for authentication.-q,--qosqos β Set the subscription QoS. Valid values are0,1, and2.-t,--topictopic β Subscribe to topic. This option may be given more than once. stack 'em bestie π§-u,--usernameusername β Set the username used for authentication.-v,--verboseβ Pass the MQTT topic as an additional command argument before the payload.--versionβ Print the program version and exit.--will-topictopic β Set the MQTT will topic.--will-payloadpayload β Set the MQTT will payload.--will-qosqos β Set the MQTT will QoS. Valid values are0,1, and2.--will-retainβ Publish the MQTT will as a retained message.--status-topictopic β Publish status transitions to topic.--status-up-payloadpayload β Set the payload used after each successful connection. If omitted, an empty payload is sent.--status-down-payloadpayload β Set the payload used on clean shutdown. This publish is best effort.--status-qosqos β Set the QoS for status publishes. Valid values are0,1, and2.--status-retainβ Publish status messages as retained messages.--ready-fdfd β Write a newline to file descriptor fd after the initial connection and subscription setup succeeds, then close it. This can be used by test harnesses or service supervisors that need an explicit readiness signal. it's basically a little "i'm ready β¨" tap on the shoulder π
π TLS OPTIONS π
When built with TLS support, the following options are available. note the when β if your build doesn't have TLS, these simply aren't there, no cap π«Ά
--cafilefile β Path to a CA certificate file.--capathdirectory β Path to a directory containing CA certificates.--certfile β Path to the client certificate.--keyfile β Path to the client private key.--cipherslist β OpenSSL-compatible cipher list.--tls-versionversion β Set the TLS protocol version.--pskkey β Set the TLS pre-shared key in hexadecimal form.--psk-identityidentity β Set the TLS PSK identity string.
π ENVIRONMENT π
MQTT_EXEC_PASSWORDβ Used as the password when--usernameis set and no password is provided on the command line. secret via env var, very spy, very demure π
π EXAMPLES π
Show MQTT messages as desktop notifications π
$ mqtt-exec -h "$mqtt_host" -t "$topic" -v --
/usr/bin/notify-send -t 3000 -i network-server
the -v is doing the work there so notify-send gets the topic too. slay.
Run a script for retained messages on startup and for later live messages π₯
$ mqtt-exec -h broker.example.com -t sensors/door -- /usr/local/bin/on-door-event
Publish presence status and process messages πΈ
$ mqtt-exec -h broker.example.com
-t sensors/door
--status-topic service/mqtt-exec/status
--status-up-payload online
--status-down-payload offline
--will-topic service/mqtt-exec/status
--will-payload failed
--status-retain
-- /usr/local/bin/on-door-event
look at all that presence info β online when it's up, offline on a clean shutdown, failed via the will if it dies unexpectedly. full personality, fully transparent, we love an accountable queen π
π§ SEE ALSO π§
mosquitto_sub(1), mosquitto_pub(1) β go read those too, they're the siblings and they also ate π
quick vibe check reminder: everything above is exactly what the page says, i just made it fun. don't come for me if you skipped the bit about the clean-shutdown publish being best effort π
this has been mqtt-exec(1) from the General Commands Manual, dated 2026-05-18, and yes the footer also says mqtt-exec(1) because it's consistent like that π
later bestie, go exec some commands π¦β¨
π¦ where this page comes from
- alpine 3.24: mqtt-exec-doc 0.7.1-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms