Skip to content

Instantly share code, notes, and snippets.

@utarn
Created October 7, 2023 07:06
Show Gist options
  • Save utarn/b43a1713cf38aa42ff11db4d2076f6f9 to your computer and use it in GitHub Desktop.
Save utarn/b43a1713cf38aa42ff11db4d2076f6f9 to your computer and use it in GitHub Desktop.
Check total byte written
#!/bin/bash
declare -A custom_names
custom_names["8427e3af:14f642d8:316fd036:e279d458"]="/root"
custom_names["f2e76944:da560738:512c4030:54026dcf"]="/opt"
for drive in /dev/sd[a-e]; do
if smartctl -A "$drive" | grep -q 'Host_Writes_GiB'; then
md_name=$(mdadm --examine "$drive" | grep "Array UUID" | awk '{print $4}')
if [ -n "$md_name" ]; then
custom_name=${custom_names["$md_name"]}
spaces_to_add=$((8 - ${#custom_name}))
# Create a string with the required spaces
padding=""
for ((i = 0; i < spaces_to_add; i++)); do
padding+=" "
done
# Combine the padding and the variable
padded_name="$padding$custom_name"
if [ -n "$custom_name" ]; then
echo -ne "$drive\tRAID Array: $padded_name\tTBW (GB): "
else
echo -ne "$drive\tRAID Array: $md_name\tTBW (GB): "
fi
else
echo -ne "$drive\tDISK\tTBW (GB):\t"
fi
smartctl -A "$drive" | awk '/Host_Writes_GiB/ {print $10}'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment