Skip to content

Instantly share code, notes, and snippets.

@benbasscom
Created March 12, 2015 18:44
Show Gist options
  • Save benbasscom/a12029f84aca3ff845ae to your computer and use it in GitHub Desktop.
Save benbasscom/a12029f84aca3ff845ae to your computer and use it in GitHub Desktop.
Drive info nicely formatted in text via bash.
#!/bin/bash
# Private Eyes log automation part 1 excerpt
# Created by Ben Bass
# Space used/Available on all attached drives.
disk_usage_raw="$(df -Hla)"
disk_name=$(echo "$disk_usage_raw" | awk -v OFS="\t" '{print $4"/"$2" free", "("$5" used)"}')
#-------------------------------------------------------------------------------------------------
echo " "
#
# Stiching the name of each drive with the info from df.
echo "-------------------------"
echo "Disk Usage Summary"
echo ""
echo -e "Volume Name"'\t''\t''\t'"Avail/Total"'\t'"Percent Used"
echo "$disk_usage_raw" | tail -n +2 | awk '{print $1}' | while read DISK_ID
do
VOL_NAME="$(diskutil info $DISK_ID | grep 'Volume Name' | cut -d : -f2 | sed 's/ //')"
PARTIAL=$(echo "$disk_usage_raw" | grep $DISK_ID | awk -v OFS="\t" '{print $4"/"$2, "("$5" used)"}')
#vol_name_ct="$(echo "$VOL_NAME" | wc -m | awk '{print $1}')"
if [ "${#VOL_NAME}" -ge 18 ]; then
echo -e "$VOL_NAME"'\t'"$PARTIAL"
elif [ "${#VOL_NAME}" -ge 15 ]; then
echo -e "$VOL_NAME"'\t''\t'"$PARTIAL"
elif [ "${#VOL_NAME}" -ge 8 ]; then
echo -e "$VOL_NAME"'\t''\t''\t'"$PARTIAL"
else
echo -e "$VOL_NAME"'\t''\t''\t''\t'"$PARTIAL"
fi
done
echo ""
echo ""
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment