You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
908 B

  1. #!/usr/bin/env bash
  2. # I use this to gather brickbot command invocations using journalctl.
  3. # Check out brickbot here --> https://github.com/theycallmemac/brickbot
  4. # I run this script every minute with a cronjob
  5. # Data scraped from this script is stored in a yaml file.
  6. main() {
  7. touch /tmp/stats.yaml
  8. rm /tmp/stats.yaml
  9. commands=("bus" "coinflip" "isitup" "luas" "nslookup" "pwgen" "pwned" "room" "ssl" "weather" "wiki" "uptime")
  10. for cmd in "${commands[@]}"; do
  11. get_invocation_count
  12. echo "$cmd: $count" >> /tmp/stats.yaml
  13. done;
  14. get_diff
  15. if [[ ($? != 0) && ($count != 0) ]]; then
  16. mv /tmp/stats.yaml /tmp/brickbot.stats.yaml
  17. fi
  18. return 0
  19. }
  20. get_invocation_count() {
  21. count=$(journalctl -u brickbot | grep Command | grep $cmd | wc -l)
  22. }
  23. get_diff() {
  24. diff /tmp/stats.yaml /tmp/brickbot.stats.yaml >> /tmp/brickbot.diffs
  25. }
  26. main || exit 1
  27. exit 0