From 155fce82e180733c0038fc7d75d9053b4d387f9c Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Tue, 5 Apr 2022 18:24:02 +0200 Subject: [PATCH] Added exit code and regex --- .../files/btrfs-health-check.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/roles/native-btrfs-health-check/files/btrfs-health-check.sh b/roles/native-btrfs-health-check/files/btrfs-health-check.sh index 5a8b7a00..a0bd83a7 100644 --- a/roles/native-btrfs-health-check/files/btrfs-health-check.sh +++ b/roles/native-btrfs-health-check/files/btrfs-health-check.sh @@ -1,6 +1,11 @@ #!/bin/bash -# Checks the healt of all btrfs volumes +exit_code=0 for path in $(btrfs filesystem show | awk '/ path /{print $NF}') do - btrfs device stats $path + echo "Checking healt for $path..." + result=$(btrfs device stats $path) + echo "$result" + regex='\.(.*)_errs(\s*)[1-9]' + [[ "$result" =~ $regex ]] && echo "Errors found!" && exit_code=1; done +exit $exit_code