Created
October 22, 2013 13:52
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#(@)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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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