Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Script to check gmail account with LED notification (Laptop users...)

  1. #1
    Join Date
    Aug 2007
    Location
    Belgium
    Beans
    176
    Distro
    Ubuntu 10.04 Lucid Lynx

    Script to check gmail account with LED notification (Laptop users...)

    Here is the script I'm using to check my gmail account automatically and give me a notification by the LED on my laptop, if you don't know how to enable your LED, I refer to the Pedric's Howto (see credits)

    Code:
    #!/bin/bash
    gmail_login="xxxxxx"
    gmail_password="xxxxx"
    mails="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
    https://${gmail_login}:${gmail_password}@mail.google.com/mail/feed/atom \
    --no-check-certificate | grep 'fullcount' \
    | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"
    if [ "$mails" -gt "0" ];
    then
    	for ((i = 0; i < 10; i++)) do
    		echo 1 > /proc/acpi/asus/mled;
    		sleep 0.8;
    		echo 0 > /proc/acpi/asus/mled;
    		sleep 0.5;
    	done
    fi
    exit
    save the script somewhere and make it executable.

    You also need to create a crontab entry for this to run every time you define:
    (I'm running it every 5 minutes)
    Code:
    00 * * * * .scripts/gmailLED.sh
    05 * * * * .scripts/gmailLED.sh
    10 * * * * .scripts/gmailLED.sh
    15 * * * * .scripts/gmailLED.sh
    20 * * * * .scripts/gmailLED.sh
    25 * * * * .scripts/gmailLED.sh
    30 * * * * .scripts/gmailLED.sh
    35 * * * * .scripts/gmailLED.sh
    40 * * * * .scripts/gmailLED.sh
    45 * * * * .scripts/gmailLED.sh
    50 * * * * .scripts/gmailLED.sh
    55 * * * * .scripts/gmailLED.sh
    Credits:
    - Gmail bash script from dbbolton
    - Howto: LED-notification by Pedric
    El Belgicano
    -----------------
    Laptop: 5 years old Asus M6N (ATI9600/9700 graphics, 512Mb RAM, Intel Mobile 1.66GHz, 60Gb HDD) running 10.04-Lucid Lynx pretty nicely.

  2. #2

    Re: Script to check gmail account with LED notification (Laptop users...)

    Moved to General Help.
    Ubuntu user #7247 :: Linux user #409907
    inconsolation.wordpress.com

  3. #3
    Join Date
    Feb 2007
    Beans
    847

    Re: Script to check gmail account with LED notification (Laptop users...)

    Instead of multiple entries in crontab, use the following code to run every 5 minutues:

    Code:
    */5 * * * * .scripts/gmailLED.sh

  4. #4
    Join Date
    Feb 2007
    Location
    Melbourne
    Beans
    799
    Distro
    Kubuntu 8.04 Hardy Heron

    Re: Script to check gmail account with LED notification (Laptop users...)

    That script is no good, because it relies on certain hardware.

    This should work on any computer.

    Code:
    sudo apt-get install blinkd
    Code:
    #!/bin/bash
    gmail_login="XXXX"
    gmail_password="XXXX"
    mails="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
    https://${gmail_login}:${gmail_password}@mail.google.com/mail/feed/atom \
    --no-check-certificate | grep 'fullcount' \
    | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"
    if [ "$mails" -gt "0" ];
    then
    blink --scrolllockled --rate=$mails;
    else
    blink -s --rate=0;
    fi
    exit
    The rate of blinking tells you how many mails are waiting for you.

    If you get a lot of mails, you could change the zero in the "if" line to two or three, so that it only bothers you when there are more mails to read. If you're happy with it alerting you of every e-mail, you could simplify the code by removing all the lines in italics in the script.

    To "snooze" it (tell it to give you another five minutes to get to gmail, type "blink -sr 0". You could make a launcher for that and stick it on your desktop.

    To tell it to stop annoying you for the rest of the session, kill the daemon. ("sudo killall blinkd")

    If the flashing doesn't work, make sure that the daemon is running. ("sudo blinkd")
    Last edited by ChameleonDave; July 4th, 2008 at 05:19 AM. Reason: grammar

  5. #5
    Join Date
    Aug 2005
    Location
    Portland, OR USA
    Beans
    57
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Script to check gmail account with LED notification (Laptop users...)

    This is one of the coolest things I've ever seen (computer-related, that is).

  6. #6
    Join Date
    Aug 2007
    Beans
    89
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Script to check gmail account with LED notification (Laptop users...)

    This is significantly awesome, but I figured voice would make it better. Here's mine:

    Code:
    #!/bin/bash
    echo "Checking for new email";
    mailsa="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
    https://name1:password1@mail.google.com/mail/feed/atom \
    --no-check-certificate | grep 'fullcount' \
    | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"
    
    echo $mailsa;
    
    mailsb="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
    https://name2:password2@mail.google.com/mail/feed/atom \
    --no-check-certificate | grep 'fullcount' \
    | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"
    
    echo $mailsb;
    
    #blink LEDs
    if [ "$mailsa" -gt "0" ];
    then
    	blink -s -r 5;
    fi
    
    if [ "$mailsb" -gt "0" ];
    then
    	blink -c -r 5;
    fi
    
    #speak announcements
    
    if [ "$mailsa" -gt "0" ];
    then
    	espeak "$mailsa new emails in main account.";
    fi
    if [ "$mailsb" -gt "0" ];
    then
    	espeak "$mailsb new emails in secondary account.";
    fi
    
    sleep 4;
    blink;
    
    exit
    It checks two email accounts. Notice that I did away with the variables containing the name and password and stuck them right in the URL. Don't remember why...

    Now, i'd like to know, is there any way to make this code more secure, IE not having my password in plain text?

  7. #7
    Join Date
    Mar 2007
    Beans
    Hidden!

    Re: Script to check gmail account with LED notification (Laptop users...)

    Thank you very much for the scripts!

    I made a mix with espeak and kdialog, which asks you for you account and password, I think is more secure.

    But I would also like to encrypt the password into the script, maybe using KWallet or GNOME Keyring.

    Code:
    #!/bin/bash
    
    echo "Write your email account."
    read gmail_login
    echo "Write your password."
    read gmail_password
    # gmail_login="XXXX"
    # gmail_password="XXXX"
    # echo -n $mail_password | md5sum | awk {'print $1'} > /dev/null
    timeout="8"
    
    mails="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
    https://${gmail_login}:${gmail_password}@mail.google.com/mail/feed/atom \
    --no-check-certificate | grep 'fullcount' \
    | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"
    if [ "$mails" -gt "0" ]; then
      kdialog --passivepopup "($mails) new emails" "$timeout";
      espeak "$mails new emails in main account.";
    else
      kdialog --passivepopup "0 new emails" "$timeout";
      espeak "0 new emails in main account.";
    fi
    exit
    It is possible to encrypt a text in MD5 (you can also use sha2)
    Code:
    echo -n $mail_password | md5sum | awk {'print $1'} > /dev/null
    but I can't use the encrypted password to login into gmail using this url.
    Code:
    https://username:password@mail.google.com/mail/feed/atom

  8. #8
    Join Date
    Mar 2009
    Location
    USA
    Beans
    538

    Re: Script to check gmail account with LED notification (Laptop users...)

    Quote Originally Posted by Xavier Oddmon View Post
    This is significantly awesome, but I figured voice would make it better. Here's mine:

    Code:
    #!/bin/bash
    echo "Checking for new email";
    mailsa="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
    https://name1:password1@mail.google.com/mail/feed/atom \
    --no-check-certificate | grep 'fullcount' \
    | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"
    
    echo $mailsa;
    
    mailsb="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
    https://name2:password2@mail.google.com/mail/feed/atom \
    --no-check-certificate | grep 'fullcount' \
    | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"
    
    echo $mailsb;
    
    #blink LEDs
    if [ "$mailsa" -gt "0" ];
    then
    	blink -s -r 5;
    fi
    
    if [ "$mailsb" -gt "0" ];
    then
    	blink -c -r 5;
    fi
    
    #speak announcements
    
    if [ "$mailsa" -gt "0" ];
    then
    	espeak "$mailsa new emails in main account.";
    fi
    if [ "$mailsb" -gt "0" ];
    then
    	espeak "$mailsb new emails in secondary account.";
    fi
    
    sleep 4;
    blink;
    
    exit
    It checks two email accounts. Notice that I did away with the variables containing the name and password and stuck them right in the URL. Don't remember why...

    Now, i'd like to know, is there any way to make this code more secure, IE not having my password in plain text?
    Very awesome. Thank you.

    I think I am going to try to set it up so it can optionally say the sender's name or otherwise look for certain subjects.

    Also, I think I will need to set cron so it does not run late at night while i sleep.
    100% Microsoft Free Since April 2, 2009

  9. #9
    Join Date
    Mar 2009
    Location
    USA
    Beans
    538

    Re: Script to check gmail account with LED notification (Laptop users...)

    Quote Originally Posted by pointone View Post
    Instead of multiple entries in crontab, use the following code to run every 5 minutues:

    Code:
    */5 * * * * .scripts/gmailLED.sh
    Just for anyone else kind of new who has their computer in the bedroom :

    Code:
    */5 9-23 * * * .scripts/gmailLED.sh
    For instance should make it run only from 9am - 11pm local time (I believe local, if not UTC?]

    Haven't tested it but it should work.
    100% Microsoft Free Since April 2, 2009

  10. #10
    Join Date
    Oct 2007
    Location
    wrong planet
    Beans
    746
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Script to check gmail account with LED notification (Laptop users...)

    I've been modifying and working on my own version of this script. Here it is. You guys try this out and see what how you like it.

    PHP Code:
    chris@ubuntu:~$ crontab -l
    # m h  dom mon dow   command
    * * * * mv /tmp/motion/*.swf /home/chris/Videos/Webcam/
    */
    * * * * /home/chris/bin/mailblinker &> /dev/null
    chris
    @ubuntu:~$ 
    PHP Code:
    chris@ubuntu:~$ which mailblinker 
    /home/chris/bin/mailblinker
    chris
    @ubuntu:~$ cat $(which mailblinker)
    #!/bin/bash
    gmail_login="xxxxxxx"
    gmail_password="xxxxxxxx"
    mails="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - \
    https://
    ${gmail_login}:${gmail_password}@mail.google.com/mail/feed/atom \
    --no-check-certificate | grep 'fullcount' \
    | sed -e 's/.*<fullcount>//;s/<\/fullcount>.*//' 2>/dev/null)"
    # Use this below to check mail from specific labels or put all to check all mails
    # https://mail.google.com/mail/feed/atom/cakes

    # blinkd only accepts blink rates of 0-29
    if [ "$mails-gt 29 ];
    then
      mails
    =29
    fi

    if [ "$mails-gt 0 ];
    then
      blink 
    ---rate=$mails
      mplayer 
    /home/chris/Downloads/sms-received5.caf &> /dev/null
    else
      
    blink ---rate=0;
    fi
    exit
    chris@ubuntu:~$ 
    To make this script work, you are going to have to put in your personal information and paths replacing mine. I've included the sound file I that plays "You've got mail!". And you will need to extract it and put the path and filename to it in the script. You need to chmod +x the script. I also might modify the script to say who the new mail(s) are from. Also having the script in ~/bin is nice because that puts it in my path, and I can type mailblinker from any directory to run the script just like any other command. If you want ~/bin to be in your path, then you need this in your ~/.profile

    PHP Code:
     19 # set PATH so it includes user's private bin if it exists                                                                       
     
    20 if [ -"$HOME/bin" ] ; then                                                                                                    
     21     PATH
    ="$HOME/bin:$PATH"                                                                                                      
     
    22 fi 
    Don't put the line numbers. Vim puts those line numbers in, and I copied it from there. If my thread helped anyone, push the thanks button.
    Attached Files Attached Files
    Last edited by go_beep_yourself; June 20th, 2009 at 09:40 AM.
    Linux Advanced Guides and News!
    http://linuxinnovations.blogspot.com/

    Green means go, Yellow means faster, Red means don't stop.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •