Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created October 22, 2013 13:52
Show Gist options
  • Save jpmens/7101170 to your computer and use it in GitHub Desktop.
Save jpmens/7101170 to your computer and use it in GitHub Desktop.
You have an MQTT broker somewhere and want to keep track of what (long-) running scripts are doing?
$ mosquitto_sub -v -t 'processes/#'
processes/run.sh Starting
processes/run.sh Still running
processes/run.sh Still going strong at Tue Oct 22 15:49:07 CEST 2013
processes/run.sh That's it, folks!
#(@)mqttfuncs.sh by Jan-Piet Mens <jpmens()gmail.com>
# Source into shell script, then:
#
# mqtt "some debug output here"
#
# to show your program is still doing something.
progname=${progname:=$(basename $0)}
topic="processes/${progname}"
mqtt_opts="--quiet -h localhost -p 1883"
function mqtt() {
# Ignore PUB errors
mosquitto_pub ${mqtt_opts} -t "${topic}" -m "$*" || true
}
#!/bin/sh
set -e
source mqttfuncs.sh
mqtt Starting
# do something ..
mqtt "Still running"
# do more (or less) of the same ..
mqtt "Still going strong at `date`"
# ...
mqtt "That's it, folks!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment