#!/usr/bin/env zsh # # Copyright (C) 2010 Nick Bowler # # Simple script which ensures that a running fetchmail daemon is # sleeping, by forcing a fetch run and waiting until it finishes. # This is useful for log rotation: the fetchmail daemon will not # write to the log file while it is sleeping. It is also useful # for manually invoking fetch runs. # # License WTFPL2: Do What The Fuck You Want To Public License, version 2. # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. setopt nonotify pid=`head -n 1 ~/.fetchmail.pid 2>/dev/null` if ! [[ $pid > 0 && $(ps --no-heading $pid) =~ fetchmail ]]; then echo "$0: fetchmail is not running." exit 1 fi coproc sed --unbuffered '/^fetchmail: sleeping/q' tail -s 0.1 -n 0 -f ~/.fetchmaillog --pid $! >&p & kill -USR1 $pid <&p wait