📜 ⬆️ ⬇️

GMail - check for new mail from the command line

Let's not pull the cat by the tail. Immediately to the point

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}}' | wc -l

The result will be the number of new letters in your inbox.


')
Update: the command can be simplified to
curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | awk -F '<fullcount>|</fullcount>' '{for (i=2; i<=NF; i++) {print $i}}'
Thanks for the tip Wolverine

Update: and even easier
curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | grep -c "<entry>"
hints onix74

The commands used should be quite familiar to the experienced linux user. For the untrained, a brief explanation of what parts of this line do.
curl - here gets the page at the specified address. In this case, this is an RSS feed.
tr -d '\ n' - removes line breaks
awk - “bites out” the necessary parts (the awk language is generally special in all sorts of string parsing. Such is the replacement of regulars)
wc -l - count the number of lines

And if the command is a little more difficult and parse the output, then you can get more information: the sender and the subject of the letter.

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/'


commandlinefu

Source: https://habr.com/ru/post/69110/


All Articles