#!/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