lots of updates, some t11 stuff
[distro-setup] / btrfsmaint
index 33cae4a36280351c170155f11fc83ba8ca3b2102..6423e26808e5da8a1279472a77962ef841e89284 100755 (executable)
@@ -102,7 +102,6 @@ main() {
   fi
 
 
-  tmp=$(mktemp)
   fnd="findmnt --types btrfs --noheading"
   for x in $($fnd --output "SOURCE" --nofsroot | sort -u); do
     mnt=$($fnd --output "TARGET" --first-only --source $x)
@@ -113,10 +112,22 @@ main() {
     # Only run for $check, since it runs in parallel to non-check, avoid
     # race condition.
     if $check; then
-      if ! btrfs dev stats -c $mnt >$tmp; then
-        if diff -q $mnt/btrfs-dev-stats $tmp; then
-          diff -u $mnt/btrfs-dev-stats $tmp | mail -s "$HOSTNAME: error: btrfs dev stats -c $mnt" root@localhost
-          cat $tmp >$mnt/btrfs-dev-stats
+      tmp=$(mktemp)
+      # if mnt is /, avoid making a buggy looking path
+      stats_path=${mnt%/}/btrfs-dev-stats
+      if [[ ! -e $stats_path ]]; then
+        btrfs dev stats -c $mnt >$stats_path ||: # populate initial reading
+      elif ! btrfs dev stats -c $mnt >$tmp; then
+        if ! diff -q $stats_path $tmp; then
+              exim -t <<EOF
+From: root@$HOSTNAME.b8.nz
+To: alerts@iankelling.org
+Subject: btrfsmaintstop: btrfs dev stats -c $mnt
+
+$(diff -u $stats_path $tmp)
+EOF
+          mv $stats_path $stats_path.1
+          cat $tmp >$stats_path
         fi
       fi
       rm -f $tmp