Skip to content

Instantly share code, notes, and snippets.

@joxl
Last active June 19, 2020 06:37
Show Gist options
  • Save joxl/56f259edb06d70a758945120c459c3d2 to your computer and use it in GitHub Desktop.
Save joxl/56f259edb06d70a758945120c459c3d2 to your computer and use it in GitHub Desktop.
Get indexing status of all volumes known to mdutil
#!/usr/bin/env bash
vols=()
maxwidth=0
while read -r vol; do
vols+=( "$vol" )
maxwidth=$(echo -e "${maxwidth}\n${#vol}" | sort -n | tail -n1)
done < <(mdutil -a 2>&1 | awk -F: '{print $1}')
fmt="%-${maxwidth}s %s\n"
for vol in "${vols[@]}"; do
# yuck, BSD sed sucks :(
# see: https://stackoverflow.com/questions/4438306/how-to-remove-trailing-whitespaces-with-sed/4438318#15416836
status=$(mdutil -s "$vol" | tail -n +2 | sed -E 's/(^[[:space:]]*|[[:space:]]*$)//g')
printf "$fmt" "$vol" "$status"
done
@joxl
Copy link
Author

joxl commented Jun 19, 2020

Rationale and example:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment