View: HTML | Text | PS | PDF | RTF | Wiki | DocBook | DocBook Inline | changelog | about this header Circle Jeff Boweron  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML v4.5//EN" "/usr/share/xml/docbook/schema/dtd/4.5/docbookx.dtd">
<article lang="en">
  <articleinfo>
    <keywordset>
      <keyword>ubuntu</keyword>
      <keyword>xmpp</keyword>
      <keyword>sendxmpp</keyword>
      <keyword>google</keyword>
      <keyword>talk</keyword>
    </keywordset>
    <title>Sending Google Talk (XMPP) Messages Using a Linux Script</title>
    <abstract>
      <para>
This document shows you how to use <package>sendxmpp</package> 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.
</para>
    </abstract>
  </articleinfo>
  <section id="install-sendxmpp">
    <title>Installing and Configuring <package>sendxmpp</package></title>
    <para>
The first thing you'll need is something called <package>sendxmpp</package>.  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 <command>sudo apt-get install sendxmpp</command> all on the same line and then hit enter.  Life's rough, I know.
</para>
    <para>
Configuring it isn't that tough either.  Let's assume your Google account is <emphasis>myusername</emphasis>, your password is <emphasis>mypassword</emphasis> and you're trying to send a message to <emphasis>myfriend</emphasis>.  To configure it just run the following commands:
</para>
    <programlisting>
touch ~/.sendxmpprc
chmod 600 ~/.sendxmpprc
echo 'myusername@gmail.com;talk.google.com mypassword' > ~/.sendxmpprc
</programlisting>
    <para>
Hmmm...  We just wrote your password to a file.  In plain text.  That's bad, isn't it?  Well, kind of.  That <command>chmod 600</command> 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 <ulink url="http://developer.pidgin.im/wiki/PlainTextPasswords">Pidgin's response</ulink>.
</para>
    <para>
You can create a bit more security by using a dedicated one-time password and enabling <ulink url="https://accounts.google.com/b/0/SmsAuthConfig">2-Factor Authentication</ulink> 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.
</para>
    <para>
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.
</para>
  </section>
  <section id="using-sendxmpp">
    <title>Using <package>sendxmpp</package></title>
    <para>
At this point you should have <package>sendxmpp</package> installed and configured.  To send a message, try running <command>echo "Enter your message here" | sendxmpp -t -u myusername -o gmail.com myfriend</command>. Note that <emphasis>myfriend</emphasis> should probably have <emphasis>myusername</emphasis> in their friends list for this to work.  Try sending yourself a message and see what happens.
</para>
    <para>
Now we can get a little more advanced.  Let's say you've installed the <package>lm-sensors</package> package and you've run <command>sensors-detect</command>.  If you want to monitor <emphasis>fan2</emphasis> to check to see if it's running above 1000RPM you can run the following script:
</para>
    <programlisting>
#!/bin/bash
&nbsp;
fanspeed=$(sensors | grep fan2 | awk '{print $2}')
&nbsp;
if [ "$fanspeed" -lt 1000 ]; then
&nbsp; echo WARNING, fan speed on $(hostname) is at $fanspeed | \
&nbsp;   sendxmpp -t -u myusername-notify -o gmail.com myusername
fi
</programlisting>
    <para>
Now you can set a crontab entry by running <command>crontab -e</command> and entering the following line:
</para>
    <programlisting>
*/5 * * * * ~/bin/check_fan
</programlisting>
    <para>
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.
</para>
    <para>
This is just one use for <command>sendxmpp</command>.  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 <ulink url="https://www.ebower.com/stoker/">stoker_mon</ulink> so I can get a message if the temperature of my BBQ goes out of range or if my food is done.
</para>
  </section>
  <!-- INCLUDE ../about-me.docbook -->
  <appendix id="about-me">
    <title>About Me</title>
    <para>
My name is Jeff Bower, I'm a <ulink url="http://www.linkedin.com/in/jdbower">technology professional</ulink> 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, including <ulink url="http://komodokamado.com/forum/">Komodo Kamado</ulink>, <ulink url="http://forum.androidcentral.com/">Android Central</ulink>, <ulink url="http://forums.virtualbox.org/">VirtualBox</ulink>, and <ulink url="http://www.makemkv.com/forum2/">MakeMKV</ulink>.  Writing these documents is a hobby of mine, I hope you find them useful and feel free to browse more at <ulink url="https://www.ebower.com/docs">https://www.ebower.com/docs</ulink>.  
</para>
    <para>
I also enjoy cooking, especially outdoors with my <ulink url="http://www.komodokamado.com">Komodo Kamado</ulink> and using my <ulink url="https://www.rocksbarbque.com">Stoker</ulink>.  Take a look at my recipes stored at <ulink url="https://www.ebower.com/recipes">https://www.ebower.com/recipes</ulink>.
</para>
    <para>
If you've got any questions or feedback please feel free to email me at <ulink url="mailto:docs@ebower.com">docs@ebower.com</ulink> or follow me on <ulink url="https://profiles.google.com/100268310848930740059">Google+</ulink> or <ulink url="http://twitter.com/jdbower">Twitter</ulink>.
</para>
  </appendix>

<!-- INCLUDE_END ../about-me.docbook -->
</article>