ff_fastd_con 696 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/sh
  2. #
  3. # Maximilian Wilhelm <max@rfc2324.org>
  4. # -- Mon 31 Aug 2015 08:55:27 AM CEST
  5. #
  6. if [ $# != 1 ]; then
  7. echo "Usage: $(basename $0) fastd_instance | -a" >&2
  8. exit 1
  9. fi
  10. fastd_con () {
  11. socket_path=$(grep "status socket" "/etc/fastd/${1}/fastd.conf" | grep -o '/[0-9a-z/_.-]\+')
  12. echo -n "$1: "
  13. socat - "UNIX-CONNECT:${socket_path}" | jq '.peers[] | select( .connection ) | .name' | wc -l
  14. }
  15. if [ "${1}" = '-a' ]; then
  16. for fastd_instance in $(find /etc/fastd -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort); do
  17. fastd_con ${fastd_instance}
  18. done
  19. else
  20. if [ ! -d "/etc/fastd/${1}" ]; then
  21. echo "Invalid fastd instance \"$1\"." >&2
  22. exit 1
  23. fi
  24. fastd_con "${1}"
  25. fi