Check your GMAIL inbox for new emails with Bash script

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.


curl -u $username:$password --silent "" |  grep -oPm1 "(?<=<title>)[^<]+" | sed '1d'

Replace the USERNAME and PASSWORD with your gmail credentials and make the script executable:

$ chmod +x

Check your gmail account inbox for new emails:

$ ./

The above bash script will print gmail XML feed atom which contains all your unread emails.


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.

Comments and Discussions
Linux Forum