# SMART and Badblocks Testing Script This script performs diagnostic tests on a specified block device using `smartctl` and `badblocks`. It enables SMART, checks device health, runs various SMART tests, and conducts a non-destructive write test. ## Prerequisites Ensure the following dependencies are installed on your system: - `smartctl` (part of the `smartmontools` package) - `badblocks` ## Usage ```bash ./smartdrivecheck.sh ``` - ``: The block device to test (e.g., `/dev/sda`). ### Example ```bash ./smartdrivecheck.sh /dev/sda ``` ## Script Workflow 1. **Dependency Check** - Verifies that `smartctl` and `badblocks` are installed and executable. 2. **Device Validation** - Ensures the specified device is a valid block device. 3. **Enable SMART** - Enables SMART on the device if it is not already enabled. 4. **SMART Data Checks** - Runs a series of checks on existing SMART data, including health status, error logs, and self-test logs. 5. **Polling Time Extraction** - Extracts polling times for various SMART self-tests (short, extended, and conveyance). 6. **Self-Tests** - Depending on available polling times, performs conveyance, short, or extended tests, waiting for their completion. 7. **Non-Destructive Write Test** - Uses `badblocks` to perform a non-destructive write test on the device. 8. **Final Extended Test** - If applicable, performs a final extended SMART test. ## Environment Variables During execution, the script extracts the following variables based on device capabilities: - `CONVEYANCE_SLEEP`: Estimated time (in minutes) for the conveyance test. - `SHORT_SLEEP`: Estimated time (in minutes) for the short test. - `EXTENDED_SLEEP`: Estimated time (in minutes) for the extended test. ## Notes - **Non-Destructive Testing**: The script ensures that the write test is non-destructive, preserving existing data on the device. - **SMART Compatibility**: This script assumes the device supports SMART. Ensure your device is compatible before running the script. ## Error Handling - The script terminates if any critical error occurs during execution. - Specific error messages will be printed to `stderr`. ## License This script is open source and available under the AGPL License. See attached License. ## Disclaimer Use this script at your own risk. Always back up your data before performing diagnostics or tests on storage devices.