Sun Apr 1 21:07:09 EEST 2012

How to quickly check unread Gmail emails on GNU / Linux - one liner script

I've hit an interesting article explaining how to check unread gmail email messages in Linux terminal. The original article is here

Being able to read your latest gmail emails in terminal/console is great thing, especially for console geeks like me.
Here is the one liner script:

curl -u GMAIL-USERNAME@gmail.com:SECRET-PASSWORD \
--silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' \
| awk -F '' '{for (i=2; i<=NF; i++) {print $i}}' \
| sed -n "s/\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 – \1/p"<br /> </code><br /><br /> <code> Linux Users Group M. – [7] discussions, [10] comments and [2] jobs on LinkedIn<br /> Twitter – Lynn Serafinn (@LynnSerafinn) has sent you a direct message on Twitter!<br /> Facebook – Sys, you have notifications pending<br /> Twitter – Email Marketing (@optinlists) is now following you on Twitter!<br /> Twitter – Lynn Serafinn (@LynnSerafinn) is now following you on Twitter!<br /> NutshellMail – 32 New Messages for Sat 3/31 12:00 PM<br /> Linux Users Group M. – [10] discussions, [5] comments and [8] jobs on LinkedIn<br /> eBay – Deals up to 60% OFF + A Sweepstakes!<br /> LinkedIn Today – Top news today: The Magic of Doing One Thing at a Time<br /> NutshellMail – 29 New Messages for Fri 3/30 12:00 PM<br /> Linux Users Group M. – [16] discussions, [8] comments and [8] jobs on LinkedIn<br /> Ervan Faizal Rizki . – Join my network on LinkedIn<br /> Twitter – LEXO (@LEXOmx) retweeted one of your Tweets!<br /> NutshellMail – 24 New Messages for Thu 3/29 12:00 PM<br /> Facebook – Your Weekly Facebook Page Update<br /> Linux Users Group M. – [11] discussions, [9] comments and [16] jobs on LinkedIn<br /> </code><br /><br /> As you see this one liner uses curl to fetch the information from <i>mail.google.com</i>'s atom feed and then uses <b>awk</b> and <b>sed</b> to parse the returned content and make it suitable for display.<br /><br /> If you want to use the script every now and then on a Linux server or your Linux desktop you can <a href="http://pc-freak.net/bshscr/quick_gmail_new_mail_check.sh"> download the above code in a script file -quick_gmail_new_mail_check.sh here </a><br /><br /> Here is a screenshot of script's returned output:<br /><br /> <img src="http://pc-freak.net/images/quick_gmail_new_mail_check-bash-script-screenshot.png" alt="Quick Gmail New Mail Check bash script screenshot" /><br /><br /> A good use of a modified version of the script is in conjunction with a 15 minutes cron job to launch for new gmail mails and launch your favourite desktop mail client.<br /> This method is useful if you don't want a constant hanging <i>Thunderbird</i> or <i>Evolution</i>, <i>pop3 / imap client</i> on your system to just take up memory or dangle down the window list.<br /> I've done a little modification to the script to simply, launch a predefined email reader program, if gmail atom feed returns new unread mails are available, <a href="http://pc-freak.net/bshscr/check_gmail_unread_mail.sh"> check or download my check_gmail_unread_mail.sh here </a><br /> Bear in mind, on occasions of errors with incorrect username or password, the script will not return any errors. The script is missing a properer error handling. Therefore, before you use the script make sure:<br /><br /> <code> gmail_username='YOUR-USERNAME';<br /> gmail_password='YOUR-PASSWORD';<br /> </code><br /><br /> are 100% correct.<br /><br /> To launch the script on 15 minutes cronjob, put it somewhere and place a cron in (non-root) user:<br /><br /> <code> # crontab -u root -e<br /> ...<br /> */15 * * * * /path/to/check_gmail_unread_mail.sh<br /> </code><br /><br /> Once you read your new emails in lets say Thunderbird, close it and on the next delivered unread gmail mails, your mail client will pop up by itself again. Once the mail client is closed the script execution will be terminated.<br /> Consised that if you get too frequently gmail emails, using the script might be annoying as every 15 minutes your mail client will be re-opened.<br /><br /> </div> <div class="posted"> <br />Posted by hip0 | <a class="link" href="../../../../../archives/2012/04/01/how_to_quickly_check_unread_gmail_emails_on_gnu__linux_-_one_liner_script/index.html">Permanent link</a> | <a href="../../../../../nbcom-1.1/cmt.php?article=/2012/04/01/how_to_quickly_check_unread_gmail_emails_on_gnu__linux_-_one_liner_script/index.html#comments"> Comments <span id="comments-e2012-04-01T21_07_09.txt"></span> <script type="text/javascript"> if (document.getElementById) { var comcnt = document.createTextNode(checkPosts("/2012/04/01/how_to_quickly_check_unread_gmail_emails_on_gnu__linux_-_one_liner_script/index.html")); document.getElementById('comments-e2012-04-01T21_07_09.txt').appendChild(comcnt); } </script></a> </div> <div class="menu"> <a href="#top">/\</a> </div> </div><!-- /archives div --> </div><!-- /container div --> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-2102595-4"); pageTracker._trackPageview(); } catch(err) {}</script> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-2102595-5"); pageTracker._trackPageview(); } catch(err) {}</script> </body> </html>