Guest User

Untitled

a guest
Nov 20th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Simple Script to remove all reatined messages for a homie device
  4. # Works great for me to get rid of devices in MQTT, which are not active anymore.
  5. # Maybe it is helpful for someone else...
  6.  
  7. echo
  8. echo "Clearing for device $1 all messages, last clean will block kill with Ctrl+C when nothing happens anymore."
  9. echo
  10. #mosquitto_sub -v -h 10.0.2.2 -t "homie/$1/#" -C $2
  11. echo "STARTING :: Checking for valid topics one after the other...."
  12.  
  13. MAX_TOPICS_TO_CHECK=100
  14.  
  15. for c in `seq 0 $MAX_TOPICS_TO_CHECK`
  16. do
  17. echo " $c Checking for Topic ...."
  18. for i in `mosquitto_sub -v -h 10.0.2.2 -t "homie/$1/#" -C 1|cut -d' ' -f1`
  19. do
  20. # echo "mosquitto_pub -h 10.0.2.2 -r -n -t \"`echo $i | sed s#'\\$'#'\\\\\\\$'#g`\""
  21. echo " $i >> sending empty payload to topic with retained flag"
  22. mosquitto_pub -h 10.0.2.2 -r -n -t "`echo $i | sed s#'\\$'#'\\\$'#g`"
  23. done
  24. done
Add Comment
Please, Sign In to add comment