Archive for February, 2015

New Email Notifying Script

Posted in Uncategorized on February 19, 2015 by Ruchira Hasaranga

Following bash script checks your mail account for every 3 minutes.


while true; do
latestid=`curl -u username:password https://mail.google.com/mail/feed/atom/ -k --silent | awk 'BEGIN{ RS="</id>"}{gsub(/.*<id>/,"");print}' | sed -n '1p' | grep -o "[0-9]*" | sed -n '2p'`

if [ ! -z "$latestid" ]; then
oldid=`cat /tmp/mailcount.txt`
if [ ! -z "$oldid" ]; then
if [ "$oldid" -lt "$latestid" ]; then
echo "new mail received"
fi
fi
echo "$latestid">/tmp/mailcount.txt
sleep 180
else
sleep 10
fi

done