2024-02-26 20:53:22 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
if [ "$#" -ne 1 ]; then
|
|
|
|
echo "Usage: $0 [short|long]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" != "short" ] && [ "$1" != "long" ]; then
|
|
|
|
echo "Invalid argument: $1"
|
|
|
|
echo "Usage: $0 [short|long]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get the list of all physical disks
|
|
|
|
declare -a disks
|
|
|
|
for disk in $(lsblk -ido KNAME | grep -v -e loop -e KNAME); do
|
|
|
|
disks+=("$disk")
|
|
|
|
done
|
|
|
|
|
|
|
|
# Run a SMART test on all disks
|
|
|
|
for disk in "${disks[@]}"; do
|
|
|
|
echo "Running $1 test on /dev/$disk"
|
|
|
|
if [ "$1" == "short" ]; then
|
2024-02-28 14:47:10 -07:00
|
|
|
sudo smartctl -t short /dev/$disk > /dev/null || true # ignore any errors running the smart command
|
2024-02-26 20:53:22 -07:00
|
|
|
elif [ "$1" == "long" ]; then
|
2024-02-28 14:36:00 -07:00
|
|
|
sudo smartctl -t long /dev/$disk > /dev/null || true
|
2024-02-26 20:53:22 -07:00
|
|
|
else
|
|
|
|
echo "Invalid argument: $1"
|
|
|
|
echo "Usage: $0 [short|long]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|