Last active
January 16, 2022 14:38
-
-
Save jagland/cd06f14ce19034d6e67b244a85ded8de to your computer and use it in GitHub Desktop.
smartgraphprobe - Probe HDDs via smartctl, export data as json, use jq to create a csv, then gnuplot to create a graph showing Power_on_time in years
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
outfile=smart.csv | |
outgraph=smart.png | |
rm $outfile | |
array=('hosts=(root@host1 user@host2 userb@host3)' 'sudo=(root sudo sudo)' 'devices=(sdb,sdd sda,sdb,sdc sda,sdb)') | |
for j in "${array[@]}"; do eval $j; done | |
tmpfile=$(mktemp) | |
let i=0 | |
for h in ${hosts[@]} | |
do | |
sudo_or_not=${sudo["$i"]} | |
for d in $(echo ${devices["$i"]} | xargs -d,) | |
do | |
if [ $sudo_or_not == "sudo" ]; then | |
ssh $h sudo smartctl -a /dev/$d -d sat -j > $tmpfile | |
else | |
ssh $h smartctl -a /dev/$d -d sat -j > $tmpfile | |
fi | |
docker run -i stedolan/jq < $tmpfile '.model_name,.device.name,.power_on_time.hours' | sed -z 's/\n/,/g;s/,$/\n/' >> $outfile | |
done | |
let i=$((i+1)) | |
done | |
docker run --rm -v $(pwd):/work remuslazar/gnuplot -e \ "set datafile separator ','; set boxwidth 0.5; set style fill solid ; set output '$outgraph'; set terminal png ; set xtics rotate ; set ylabel 'years' ; set xlabel 'disk' ; set key noautotitle ; plot '$outfile' using (\$3/8670):xtic(1) with boxes" | |
rm $tmpfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment