This is a simple script that checks a
Gmail account, and turns on the ThinkLight on a ThinkPad laptop when there're unread emails.
The script includes the email address and login in unencrypted form, so it might be advisable to come up with a neater solution :o) But I hope this can be of some inspiration:
#!/bin/bash
# We'll turn on the ThinkLight if there're unread emails
# checking for new emails
rm /home/username/bash/tmp/atom
wget --no-check-certificate -q -P/home/username/bash/tmp/ https://gmail-username:gmail-password@mail.google.com/mail/feed/atom
email=`perl -ne 'while(/author/g){++$count}; print "$count\n"' /home/username/bash/tmp/atom`
echo $email
if [ -n "$email" ]; then
email=$email
echo "There are new emails"
echo on | sudo tee /proc/acpi/ibm/light
else
echo "There are no new emails"
email=0
echo off | sudo tee /proc/acpi/ibm/light
fi
The script uses the directory
/home/username/bash/tmp/ to store the file downloaded from Gmail, so that dir has to exist.
If you save the script as
checkmail and make it executable (with
chmod 777 checkmail), you'll be able to make the script run in the background with:
sudo watch --interval=300 ./checkmail &> /dev/null &