Thanks Mark, very usefull your script, i already fix mine with something similar that you post
the script looks now like this and works just as i want
echo "Checking if exist internet connection"
ping -c 3 www.google.com
if [ $? -eq 0 ]; then
echo "Starting to send & download email"
echo "Flushing mail queue"
/usr/sbin/postqueue -c /etc/postfix -f
echo "Starting fetchmail"
/usr/bin/fetchmail -v -f /etc/fetchmailrc -L /var/log/fetchmail.log
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"
echo "Terminating the connection"
echo "Internet connection not found"
now i have another issue. as this script runs automatically when ppp0 comes up and not manually or by a cron job, how can i see the output of this script when it runs? may be logging it to some file under /var/log or there is some other way to see it when it is running? how this can be done?