diff --git a/btrfs-errmail.service b/btrfs-errmail.service new file mode 100644 index 0000000..89d4d79 --- /dev/null +++ b/btrfs-errmail.service @@ -0,0 +1,7 @@ +[Unit] +Description=Check for btrfs issues and send an email if any were found +Documentation=man:btrfs + +[Service] +Type=simple +ExecStart=/usr/share/btrfsmaintenance/btrfs-errmail.sh diff --git a/btrfs-errmail.sh b/btrfs-errmail.sh new file mode 100755 index 0000000..546c086 --- /dev/null +++ b/btrfs-errmail.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Copyright (c) 2022 Matthias Klumpp + +umask 022 +PATH=/sbin:/bin:/usr/sbin:/usr/bin +export PATH + +if [ -f /etc/sysconfig/btrfsmaintenance ] ; then + . /etc/sysconfig/btrfsmaintenance +fi + +if [ -f /etc/default/btrfsmaintenance ] ; then + . /etc/default/btrfsmaintenance +fi + +. $(dirname $(realpath "$0"))/btrfsmaintenance-functions + +if [ -z "$BTRFS_MAILADDR" ] +then + # no email set, nothing to do for us + exit 0 +fi + +BTRFS_STATS_MOUNTPOINTS=$(expand_auto_mountpoint "auto") +OIFS="$IFS" +IFS=: +for MM in $BTRFS_STATS_MOUNTPOINTS; do + if ! is_btrfs "$MM"; then + echo "Path $MM is not btrfs, skipping" + continue + fi + devstats=$(btrfs device stats --check $MM 2>&1) + if [ $? -ne 0 ]; then + mail_body="$(sendmail -t <