curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;'

Check your unread Gmail from the command line

notice what happens when there is more than one unread message in a thread... also people please dont hardcode the password when you use curl. Leave it out and curl will ask you when it runs. Please...?
Sample Output
Thank You!
        name-elided
Your LWN. subscription expires soon
        LWN Subscriptions
Interesting reading
        name-elided
bash completion code question
        me
        name-elided
this and that
        name-elided
        me
RE: Relocating to name-elided
        name-elided
        me

100
By: sitaram
2009-09-08 06:53:39

4 Alternatives + Submit Alt

  • Checks the Gmail ATOM feed for your account, parses it and outputs a list of unread messages. For some reason sed gets stuck on OS X, so here's a Perl version for the Mac: curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*<name>(.*)<\/name>.*$/$2 - $1/' If you want to see the name of the last person, who added a message to the conversation, change the greediness of the operators like this: curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*?<name>(.*?)<\/name>.*$/$2 - $1/' Show Sample Output


    46
    curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"
    postrational · 2009-09-07 21:56:40 6
  • Just an alternative with more advanced formating for readability purpose. It now uses colors (too much for me but it's a kind of proof-of-concept), and adjust columns. Show Sample Output


    3
    curl -u username --silent "https://mail.google.com/mail/feed/atom" | awk 'BEGIN{FS="\n";RS="(</entry>\n)?<entry>"}NR!=1{print "\033[1;31m"$9"\033[0;32m ("$10")\033[0m:\t\033[1;33m"$2"\033[0m"}' | sed -e 's,<[^>]*>,,g' | column -t -s $'\t'
    frntn · 2011-10-15 23:15:52 0

  • -1
    mtr www.google.com
    slu4aen · 2014-10-08 06:55:32 0
  • notice what happens when there is more than one unread message in a thread... also people please dont hardcode the password when you use curl. Leave it out and curl will ask you when it runs. Please...?


    -6
    curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "$2\n" if /<(title|name)>(.*)<\/\1>/;
    suxer · 2009-09-09 23:25:05 1

What Others Think

Please don't copy from others
suxer · 454 weeks and 1 day ago
If you have libwww-perl installed, you can use the decode_entities function from HTML::Entities. This will make HTML entities like  , ", etc. look prettier. curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -MHTML::Entities -ne 'print "\t" if /<name>/; print decode_entities($2)."\n" if /<(title|name)>(.*)<\/\1>/;'
archtaku · 342 weeks and 1 day ago
LOL, and of course my comments show them as their decoded form. I am of course referring to the & nbsp; & quot;, etc. (I put a space between the ampersand and the rest of the entity.
archtaku · 342 weeks and 1 day ago
You have to disable gmail security features to be able to use this now.
scurge · 157 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: