New Email Notifying Script

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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: