Shell Person Help me keep the shell people alive.

21Jun/095

Quickly Check Gmail with BASH

bells

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.

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.

Tagged as: , , , 5 Comments