View: HTML | Text | PS | PDF | RTF | Wiki | DocBook | DocBook Inline | changelog | about this header Circle Jeff Boweron  
Sending Google Talk (XMPP) Messages Using a Linux Script

Sending Google Talk (XMPP) Messages Using a Linux Script

This document shows you how to use sendxmpp to send a Google Talk message based on a script. This is useful utility for notifications, for example warning you that a website has changed or that a log message has appeared.


Table of Contents
1. Installing and Configuring sendxmpp
2. Using sendxmpp
A. About Me

1. Installing and Configuring sendxmpp

The first thing you'll need is something called sendxmpp. This allows you to send XMPP messages; XMPP is the underlying protocol around Google Talk as well as many other open instant messaging protocols. Installing it under Ubuntu is very difficult, you need to type in sudo apt-get install sendxmpp all on the same line and then hit enter. Life's rough, I know.

Configuring it isn't that tough either. Let's assume your Google account is myusername, your password is mypassword and you're trying to send a message to myfriend. To configure it just run the following commands:


touch ~/.sendxmpprc
chmod 600 ~/.sendxmpprc
echo 'myusername@gmail.com;talk.google.com mypassword' > ~/.sendxmpprc

Hmmm... We just wrote your password to a file. In plain text. That's bad, isn't it? Well, kind of. That chmod 600 command means that only you can read that file so anyone who can see it has already compromised your account. Encrypting it is a false sense of security because you need to be able to decrypt it as well. For a much better explanation you can check out Pidgin's response.

You can create a bit more security by using a dedicated one-time password and enabling 2-Factor Authentication for your Google account. In this mode you need a password as well as an app for your smartphone to log in. These one-time passwords provide vulnerability, but you can disable them quickly and you can't log into your Gmail account with them. Now if your password is compromised you can disable it quickly. Again, not ideal but better than without 2FA.

Luckily, there's another option. It's not very expensive nor difficult to set up a dedicated Google account for this. You can set up a "notifications" account with a dedicated, unique password for this setup. Now you're not just protected by securing your own computer but you're also protected because this Google account has no meaningful email.


2. Using sendxmpp

At this point you should have sendxmpp installed and configured. To send a message, try running echo "Enter your message here" | sendxmpp -t -u myusername -o gmail.com myfriend. Note that myfriend should probably have myusername in their friends list for this to work. Try sending yourself a message and see what happens.

Now we can get a little more advanced. Let's say you've installed the lm-sensors package and you've run sensors-detect. If you want to monitor fan2 to check to see if it's running above 1000RPM you can run the following script:


#!/bin/bash
 
fanspeed=$(sensors | grep fan2 | awk '{print $2}')
 
if [ "$fanspeed" -lt 1000 ]; then
  echo WARNING, fan speed on $(hostname) is at $fanspeed | \
    sendxmpp -t -u myusername-notify -o gmail.com myusername
fi

Now you can set a crontab entry by running crontab -e and entering the following line:


*/5 * * * * ~/bin/check_fan

Every five minutes your system will check the fan speed and, if it drops below 1000, you'll get a Google Talk message with the current speed. Note that this is pretty dumb and will continue to send you a message as long as the fan is below 1000, but it's easy to add smarts to only send you a message once when it drops below 1000 and again when it's above 1000.

This is just one use for sendxmpp. I use it to monitor a web page for changes that indicate that my CM7 build has been updated. I'll also be incorporating it into stoker_mon so I can get a message if the temperature of my BBQ goes out of range or if my food is done.


A. About Me

My name is Jeff Bower, I'm a technology professional with more years of experience in the telecommunications industry than I'd care to admit. I tend to post with the username jdbower on various forums. Writing these documents is a hobby of mine, I hope you find them useful and feel free to browse more at https://www.ebower.com/docs.

If you've got any questions or feedback please feel free to email me at docs@ebower.com or follow me on Google+ or Twitter.