In case you wish to automate your things with your gmail email. Here is a simple script on how to access your gmail account with bash script. Before you run the script make sure that curl command is available on your system as this script depends on it. The below script is a great way to quickly check your gmail inbox with a single command. Open your favorite text edit and create a bash script file with some arbitrary file name eg. check_email.sh
#!/bin/bash

username="USERNAME"
password="PASSWORD"
echo
curl -u $username:$password --silent "https://mail.google.com/mail/feed/atom" |  grep -oPm1 "(?<=<title>)[^<]+" | sed '1d'
Replace the USERNAME and PASSWORD with your gmail credentials and make the script executable:
$ chmod +x check_email.sh
Check your gmail account inbox for new emails:
$ ./check_email.sh
The above bash script will print gmail XML feed atom which contains all your unread emails.

Troubleshooting

In case the above script does not produce any output check whether you have received an email from google with title:
Google Account: sign-in attempt blocked
The email will contain instructions on how to allow your bash script to access your gmail inbox.
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.

You may also be interested in:



Comments and Discussions