while ! postqueue -p | grep -q empty; do
sleep 1
done
killall wvdial
此脚本检查我的邮件队列是否为空,然后断开我的调制解调器。现在我想还添加一个检查 fetchmail 是否正在运行的功能。我不确定如何开发它,但我知道它可以类似于下面的示例。
while ! postqueue -p | grep -q empty && "fetchmail process is not running"; do
请帮忙吗?
答案1
echo "Checking mail queue and fetchmail process"
while ! postqueue -p | grep -q empty && ps -C fetchmail > /dev/null; do
echo "There is still mail in queue or fetchmail is still working"
sleep 1
done
echo "Terminating the connection"
killall wvdial
答案2
while [ "`find /var/spool/postfix/{deferred,active,maildrop}/ -type f | wc -l`" -gt 0 ] ||
[ "`ps -C fetchmail -o pid= | wc -l`" -gt 0 ]; do
sleep 5
done
killall wvdial
或者甚至产生更少的进程:
while [ -n $("find /var/spool/postfix/{deferred,active,maildrop}/ -type f") ] ||
[ -n $("ps -C fetchmail -o pid=") ]; do
sleep 5
done
killall wvdial