From 1633bb797052e46e82f562297ed690fe302ca0e3 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Mon, 26 Feb 2024 20:53:22 -0700 Subject: [PATCH] add smartctl-test-disks --- Other/smartctl-test-disks.sh | 32 ++++++++++++++++++++++ services/smartctl-test-disks-long.service | 11 ++++++++ services/smartctl-test-disks-long.timer | 9 ++++++ services/smartctl-test-disks-short.service | 11 ++++++++ services/smartctl-test-disks-short.timer | 9 ++++++ 5 files changed, 72 insertions(+) create mode 100755 Other/smartctl-test-disks.sh create mode 100644 services/smartctl-test-disks-long.service create mode 100644 services/smartctl-test-disks-long.timer create mode 100644 services/smartctl-test-disks-short.service create mode 100644 services/smartctl-test-disks-short.timer diff --git a/Other/smartctl-test-disks.sh b/Other/smartctl-test-disks.sh new file mode 100755 index 0000000..f4f4a76 --- /dev/null +++ b/Other/smartctl-test-disks.sh @@ -0,0 +1,32 @@ +#!/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 + elif [ "$1" == "long" ]; then + sudo smartctl -t long /dev/$disk > /dev/null + else + echo "Invalid argument: $1" + echo "Usage: $0 [short|long]" + exit 1 + fi +done diff --git a/services/smartctl-test-disks-long.service b/services/smartctl-test-disks-long.service new file mode 100644 index 0000000..f94fb5a --- /dev/null +++ b/services/smartctl-test-disks-long.service @@ -0,0 +1,11 @@ +[Unit] +Description=Smartctl Run Short Test + +[Service] +User=nagios +ExecStart=/opt/icinga2-checks/Other/smartctl-test-disks.sh long +SyslogIdentifier=smartctl-test-disks +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/services/smartctl-test-disks-long.timer b/services/smartctl-test-disks-long.timer new file mode 100644 index 0000000..0404209 --- /dev/null +++ b/services/smartctl-test-disks-long.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Smartctl Run Short Test every week + +[Timer] +OnBootSec=monthly +OnUnitActiveSec=monthly + +[Install] +WantedBy=timers.target \ No newline at end of file diff --git a/services/smartctl-test-disks-short.service b/services/smartctl-test-disks-short.service new file mode 100644 index 0000000..fb21ec8 --- /dev/null +++ b/services/smartctl-test-disks-short.service @@ -0,0 +1,11 @@ +[Unit] +Description=Smartctl Run Short Test + +[Service] +User=nagios +ExecStart=/opt/icinga2-checks/Other/smartctl-test-disks.sh short +SyslogIdentifier=smartctl-test-disks +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/services/smartctl-test-disks-short.timer b/services/smartctl-test-disks-short.timer new file mode 100644 index 0000000..a21fb29 --- /dev/null +++ b/services/smartctl-test-disks-short.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Smartctl Run Short Test every week + +[Timer] +OnBootSec=weekly +OnUnitActiveSec=weekly + +[Install] +WantedBy=timers.target \ No newline at end of file