gmail notifier

If you want to use MyBook lights for something useful, not just to see, if the disk is turning, or the disk is too warm,if you have a gmail account, you can use gmail notifier to see if there are unread emails in your inbox.


What it does:

The gmail notifier is a bash script, which downloads xml atom file, then counts number of unread mails and then it blinks, if there's something new.
It checks every 30 minutes for mail. At night it turns off lights(I like it that way). It needs minimum traffic. Let's say max 0.6kb*2*24h*30d~=1MB per month.(actually 2/3 of it, because at night it doesn't download anything).

Requirements:

MyBook 1st edition, you must check commands to turn on/off lights on 2nd edition(may be the same).
ssh enabled
optware installed
$PATH with optware is optional, or you could specify the path manually in script.
wget-ssl package installed. (ipkg install ssl). Remove standard wget form optware, if it promts for it.

Installation:

see code.

Disadvantages:

When you read it, you have to wait another 30minutes, when the lights turn down. It has some flows, but it's indeed useful.
Another "bug" is, that the script doesn't check certificate and it wakes up the disk(wget to stdout would help). These are all TODOs.
It could ping my laptop's IP and when I'm online, it could checks more often, if I read mails.

Code:

#!/bin/bash
# Gmail lights notifier for WD MyBook World 1st ed.
#     The blue ring on MyBook will blink, when the mail arrives.
#
# Author: Marcel Kanta
#
# Licence: GPLv2 or greater
#
# Installation: 1. Specify http-user and http-password 
#        in ~/.wgetrc and chmod 600 it for security.
#    2. You should have optware and wget-ssl package installed on MyBook.
#    3. Add the path in script to optware's wget, or add /opt/bin to $PATH.
#    4. chown YourUser /sys/class/leds/wdc-leds:power/brightness
#    and chown YourUser /sys/class/leds/wdc-leds:fuel-gauge/brightness
# Start: Try "nohup sh gmail_lights.sh >/dev/null&"
# Notes: 1. TODO: --no-check-certificate parameter is not so secure
#     2. Edit this script and you can get Binary weather forecast
#        (could notifies you, if it rains tomorrow)
#     3. enjoy :)

while true; do #maybe cron will do this job better

HOUR=`date | tr -s " "|tr ":" " "| cut -d " " -f 4`

if [ $HOUR -le 22 ] && [ $HOUR -ge 8 ]; then
    #get and parse xml output for number of unread mails
    wget --no-check-certificate https://mail.google.com/mail/feed/atom -O atom$$ 2>/dev/null
    if [ `grep -c "<entry>" <atom$$` -eq 0 ]; then #turn off the lights
        chmod u+w /sys/class/leds/wdc-leds:power/brightness
        echo 0 > /sys/class/leds/wdc-leds:power/brightness
        echo 0 > /sys/class/leds/wdc-leds:fuel-gauge/brightness
        chmod u-w /sys/class/leds/wdc-leds:power/brightness
    else    # you've got the mail! :)
        chmod u+w /sys/class/leds/wdc-leds:power/brightness
        echo 1 > /sys/class/leds/wdc-leds:power/brightness
        echo 1 > /sys/class/leds/wdc-leds:fuel-gauge/brightness
        chmod u-w /sys/class/leds/wdc-leds:power/brightness
    fi;
    rm atom$$;

else    #sleep at night
    chmod u+w /sys/class/leds/wdc-leds:power/brightness             
    echo 0 > /sys/class/leds/wdc-leds:power/brightness              
    echo 0 > /sys/class/leds/wdc-leds:fuel-gauge/brightness         
    chmod u-w /sys/class/leds/wdc-leds:power/brightness
    sleep 1800;#checks every hour
fi;
sleep 1800; 

done
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License