Quickly Check Gmail with BASH

A very simple script to check if I have any new gmail:
#!/bin/bash ## Quickly checks if I have new gmail echo -e "Checking for new messages... \c" atomlines=`wget -T 3 -t 1 -q --secure-protocol=TLSv1 \ --no-check-certificate \ --user=USERNAME --password=PASSWORD \ https://mail.google.com/mail/feed/atom -O - \ | wc -l` echo -e "\r\c" [ $atomlines -gt "8" ] \ && echo -e " You have new gmail. \c" \ || echo -e " No new gmail. \c"
Just replace USERNAME and PASSWORD with your information (caution - your password is stored in plain text). I use colors on mine, but I'm not sure I can correctly post the requisite special character in WordPress. Here's what it looks like in gedit.

I can make that special character in gnome-terminal by pressing CTRL+v and then CTRL+[
There's probably an easier way to use colors, I just don't know it.
In case it's not clear from the script, this just downloads the atom feed (an XML file) and checks if it's more than eight lines long. If it is, then you have unread mail. (At least on my account, when my inbox has no unread items, the atom feed is eight lines long). The number may need to be adjusted if gmail changes the format of their feeds.
November 14th, 2009 - 20:41
You can shorten that wget line a fair bit with curl:
curl -su user:pass https://mail.google.com/mail/feed/atom
November 14th, 2009 - 21:07
Thanks Adam, I’ve never used curl for anything before, but I’ll check it out.
February 6th, 2011 - 03:45
Adam rocks!!! curl is clean,fast and simple. thanks.
March 31st, 2011 - 18:51
Good stuff!
You may also hide your password by using something like:
echo -n “password:”
read -es mypass
then changing your wget to:
atomlines=`wget -T 3 -t 1 -q –secure-protocol=TLSv1 \
–no-check-certificate \
–user=USERNAME –password=$mypass
Cheers!