fixes
[distro-setup] / mailtest-check
index 5cf79fe8278b8ae69532ee66fb17b60e49ac793a..89ed00c1cd54e10f51e31d4c784ab2f7e2e78f6f 100755 (executable)
@@ -131,13 +131,14 @@ EOF
       fi
       # webmail sends them to cur it seems
       while read -r file; do
-        if [[ $file -nt $latest ]]; then
+        file_sec=$(awk '/^Subject: / {print $4}' $file)
+        if [[ $file_sec ]] && (( file_sec > last_sec )); then
           latest=$file
+          last_sec="$file_sec"
         fi
       done <$tmpfile
 
       to=$(awk '/^Envelope-to: / {print $2}' $latest)
-      last_sec=$(awk '/^Subject: / {print $4}' $latest)
 
       if $slow; then
         if ! $int; then
@@ -236,6 +237,7 @@ EOF
             #fi
           fi
           rm -f $resultfile
+          unexpected=$(( unexpected + ${#results[@]} + ${#missing[@]} ))
         fi # if spamdpid
       fi # if $slow
 
@@ -247,9 +249,8 @@ EOF
       pr <<EOF
 mailtest_check_last_usec{folder="$folder",from="$from"} $last_sec
 EOF
-    done
-    unexpected=$(( unexpected + ${#results[@]} + ${#missing[@]} ))
-  done
+    done # end for from in ${froms[@]}
+  done # end for folder in ${folders[@]}
   if $slow; then
     pr <<EOF
 mailtest_check_unexpected_spamd_results $unexpected
@@ -264,10 +265,13 @@ EOF
 }
 
 loop-main() {
+  # When running under systemd, the system just started. Ve nice and
+  # give programs some time to finish their startup.
+  sleep 5
   while true; do
     premain_sec=$EPOCHSECONDS
     main
-    sleep $(( 300 - ( $EPOCHSECONDS - premain_sec ) ))
+    sleep $(( 300 - ( EPOCHSECONDS - premain_sec ) ))
   done
 }