Skip to content

Instantly share code, notes, and snippets.

@ibressler
Last active August 14, 2025 10:58
Show Gist options
  • Select an option

  • Save ibressler/b16793cc5173058c1d5e18d3d39a2a59 to your computer and use it in GitHub Desktop.

Select an option

Save ibressler/b16793cc5173058c1d5e18d3d39a2a59 to your computer and use it in GitHub Desktop.
Retrieve the S.M.A.R.T. & FARM meta data of a given disk and store it to a file named by its model, serial number and the current date.
#!/bin/sh
# Retrieve the S.M.A.R.T. & FARM meta data of a given disk and store
# it to a file named by its model, serial number and the current date.
devpath="$1"
if [ ! -e "$devpath" ]; then
echo "Please provide an existing device path!"
exit 1
fi
cmd=smartctl
cmd1="$cmd -x $devpath"
cmd2="$cmd -l farm $devpath"
out1="$($cmd1)"
out2="$($cmd1)"
devid="$(echo "$out1" | awk -F: '
BEGIN{model=""}
/Device Model:/{sub("^\\s+","",$2); n=split($2,a,"\\s+"); model=a[n]}
/Serial Number:/{sub("^\\s+","",$2); serial=$2}
END{print model"-"serial}')"
outfn="${cmd}_${devid}_$(date +%y%m%d).txt"
cat << EOF > "$outfn"
# $cmd1
$out1
# $cmd2
$out2
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment