chiark / gitweb /
pull-mail: add --force option; extend running times
[bin.git] / pull-mail
index a1959505a4f34f5000b544725d255c14330d8154..2a33895f9d0e90413e60dee3b5ad1ed1925e4f10 100755 (executable)
--- a/pull-mail
+++ b/pull-mail
@@ -1,9 +1,24 @@
 #! /bin/sh
 
-if ! [ -e ~/.nomail ]; then
-    date >> ~/.fetchmail/log
-    fetchmail >> ~/.fetchmail/log
-    bsmtp-pull gluck
+if [ -f ~/.nomail ] && [ "$1" != --force ]; then
+       exit 0
 fi
 
+loadavg="$(cut -d. -f1 /proc/loadavg)"
+if [ "$loadavg" -ge 5 ] && [ "$1" != --force ]; then
+       # System load is too high. Don't contribute to it.
+       exit 0
+fi
+
+bsmtp-pull master
+
+hour="$(date +%H)"
+case $hour in
+    0[0-4789]|[12]*)
+       date >> ~/.fetchmail/log
+       fetchmail >> ~/.fetchmail/log
+       logrotate -s ~/.fetchmail/logrotate.status ~/.fetchmail/logrotate.conf
+       ;;
+esac
+
 exit 0