The following is the GNU All-permissive License as recommended in https://www.gnu.org/licenses/license-recommendations.en.html

Copyright (C) 2024 Free Software Foundation sysadmin@fsf.org

Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.

Contributions are welcome. See https://savannah.gnu.org/maintenance/fsf/.

smartctl

To test drives with the SMART / S.M.A.R.T. capabilities:

# install smartctl
apt install smartmontools

# check most of the stored SMART data
smartctl -a /dev/sda

# start a long test (it will tell you how long it should take)
smartctl -t long /dev/sda

If you get an error about not being able to determine if the drive is SATA or SCSI, etc, then you may want to look up the -d option in the man page, or if you know it's SATA based, just try -d sat to the command line invocations of smartctl.

# check the test results (you can check during the test too)
smartctl -l selftest /dev/sda

When using the -l option, you want to see a blank entry or a - for LBA_of_first_error, and 00% for Remaining. At that point, the test is done. If there is an LBA reported, then that means that that test failed.

Sometimes it can be helpful to check dmesg for certain kinds of errors, but the testing is performed within the disk itself.

As long as the disks keep power and aren't suspended by the kernel or your motherboard, they should run in the background. If the tests are automatically interrupted by disks getting suspended due to inactivity, you can write a bash loop that reads a single block from the device about once every minute.