Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Main Support Categories > General Help
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

General Help
All your general support questions for Ubuntu, Kubuntu, Edubuntu and Xubuntu.

 
Thread Tools Display Modes
Old May 30th, 2008   #1
El_Belgicano
A Carafe of Ubuntu
 
El_Belgicano's Avatar
 
Join Date: Aug 2007
Location: Belgium
Beans: 114
Ubuntu 7.10 Gutsy Gibbon
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: Asus M6N, ATI 9600/9700, 512RAM, Intel Mobile 1.66GHz, 60Gb, Dual boot: Ubuntu 7.10 (Soon to become 8.10 Ibex) & Win XP.
El_Belgicano is offline   Reply With Quote
Old May 30th, 2008   #2
K.Mandla
午後の紅茶 お願いします
 
K.Mandla's Avatar
 
Join Date: Feb 2006
Location: Japan
Beans: 5,738
Ubuntu
Re: Script to check gmail account with LED notification (Laptop users...)

Moved to General Help.
__________________
Ubuntu user #7247 :: Linux user #409907
Motho ke motho ka botho :: Buy old, not new :: Keep your old computer :: Things to do with it
K.Mandla is offline   Reply With Quote
Old May 30th, 2008   #3
pointone
100% Pure Ubuntu
 
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
pointone is offline   Reply With Quote
Old July 3rd, 2008   #4
ChameleonDave
Day Old Decaf
 
Join Date: Feb 2007
Location: Melbourne
Beans: 799
Kubuntu 8.04 Hardy Heron
Send a message via ICQ to ChameleonDave Send a message via AIM to ChameleonDave Send a message via MSN to ChameleonDave Send a message via Yahoo to ChameleonDave Send a message via Skype™ to ChameleonDave
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 12:19 AM.. Reason: grammar
ChameleonDave is offline   Reply With Quote
Old July 4th, 2008   #5
tom957
5 Cups of Ubuntu
 
tom957's Avatar
 
Join Date: Aug 2005
Location: Portland, OR USA
Beans: 33
Ubuntu 9.04 Jaunty Jackalope
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).
tom957 is offline   Reply With Quote
Old September 25th, 2008   #6
Xavier Oddmon
Just Give Me the Beans!
 
Xavier Oddmon's Avatar
 
Join Date: Aug 2007
Beans: 75
Ubuntu 9.10 Karmic Koala
Send a message via AIM to Xavier Oddmon Send a message via MSN to Xavier Oddmon
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?
Xavier Oddmon is offline   Reply With Quote
Old April 19th, 2009   #7
paradigm2
Dipped in Ubuntu
 
Join Date: Mar 2009
Location: USA
Beans: 530
Ubuntu 9.10 Karmic Koala
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
All info is best effort only. While I hope it is correct no warranty is implied.
paradigm2 is offline   Reply With Quote
Old June 20th, 2009   #8
go_beep_yourself
Skinny Soy Caramel Ubuntu
 
go_beep_yourself's Avatar
 
Join Date: Oct 2007
Location: wrong planet
Beans: 662
Ubuntu 9.10 Karmic Koala
Send a message via ICQ to go_beep_yourself Send a message via AIM to go_beep_yourself Send a message via MSN to go_beep_yourself Send a message via Yahoo to go_beep_yourself Send a message via Skype™ to go_beep_yourself
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
File Type: bz2 sms-received5.caf.bz2 (6.6 KB, 2 views)
__________________
Linux HowTos and Free Support!
http://linuxinovations.blogspot.com/

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

Last edited by go_beep_yourself; June 20th, 2009 at 04:40 AM..
go_beep_yourself is offline   Reply With Quote
Old June 20th, 2009   #9
geo909
Quad Shot of Ubuntu
 
geo909's Avatar
 
Join Date: May 2007
Location: Crete, Greece
Beans: 508
Re: Script to check gmail account with LED notification (Laptop users...)

Thanks for this thread! This is an amazing idea
geo909 is offline   Reply With Quote

Bookmarks

Tags
gmail, laptop, led, script

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:07 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. lingonberry