- Home
- Contact
-
Articles / Code
- HTML/CSS (2)
-
Scripts (17)
- Twitter & bash
- Generate sitemaps
- random floating point in bash
- Gmail script
- Python http POST requests
- Bashrc enhancements
- commandline <> nautilus
- Word Definitions
- Synonyms
- mysqld monitor
- remote server
- links and emailaddresses
- Apache Analyser
- remote ipaddress
- OOP Python
- mysql tuning
- diskspace notification
- Server Configuration (6)
- ICT-security (2)
Gmail use command-line to check for new messages
» Articles / Code » Scripts » Gmail use command-line to check for new messages
bash script for checking your gmail accounts
(This is probably one of the scripts that I use the most)
Having multiple gmail accounts can be usefull, however opening your browser, logging in and out (multiple times) is annoying, especially when there wasn't really a new email.
This bash script checks your gmail accounts, and reports how many new messages are in your inbox. Also, it activates your ScrLock led on your keyboard (really, when did you use that button anyway...?).
To get the led function working, you might have to do this first:
lxer@local:~$ xmodmap -e 'add mod3 = Scroll_Lock'
or add it to modmap: nano ~/.Xmodmap , add mod3 = Scroll_Lock
#! /bin/bash
# checking for new emails @ gmail
# created by Lxer 2008
#
# check your modifier keysettings: xmodmap
# to get scroll lock led working: xmodmap -e 'add mod3 = Scroll_Lock'
# or add it to modmap: gedit ~/.Xmodmap , add mod3 = Scroll_Lock
# to have this script running in the background and checking
# it repeatedly, use:
# sudo watch --interval=300 gmail &> /dev/null &
# or set as cronjob
#
#####################
# replace these with your account settings :
username=( username1 username2 username3 )
passwd=( pass1 pass2 pass3 )
tempfile="/var/tmp/gm/"
#########
a=0
for (( i = 0 ; i < ${#username[@]} ; i++ )) ; do
wget -q -P $tempfile https://${username[$i]}:${passwd[$i]}@mail.google.com/mail/feed/atom
if [ -f $tempfile"atom" ]; then
email=`sed -n -e 's/<\/*fullcount>//pg' $tempfile"atom"`
if [ "$email" != "0" ]; then
echo -e "New emails: \033[1m $email \033[0m account: \033[1m ${username[$i]} \033[0m"
sed -n -e 's/< \/*summary>/\r/pg' $tempfile"atom"
a=1
fi
rm $tempfile"atom"
else
echo $name3 : Login failed.
fi
done
# print url for easy access
if [ $a -eq 1 ]; then
echo "http://www.gmail.com"
fi
#blinkenlight
if [[ $EUID -eq 0 ]]; then # only if root
if [ $a -eq 1 ]; then
ledcontrol set s5 on
else
ledcontrol set s5 off
fi
fi
Save this file as, for example, 'gmail' and put it in your /usr/bin folder (and make it executable). A cronjob can be used to run this script like every 5 minutes or so.
Post your comment
Comments
No one has commented on this page yet.
RSS feed for comments on this page | RSS feed for all comments