icinga2-checks/Other/smartctl-test-disks.sh

33 lines
811 B
Bash
Executable File

#!/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
sudo smartctl -t short /dev/$disk > /dev/null || true # ignore any errors running the smart command
elif [ "$1" == "long" ]; then
sudo smartctl -t long /dev/$disk > /dev/null || true
else
echo "Invalid argument: $1"
echo "Usage: $0 [short|long]"
exit 1
fi
done