November 16, 2018
XMPP via the command-line with sendxmpp
sendxmpp is a XMPP client for the command-line. It’s basically a Perl-script and it’s intended to be an alternative to sendmail.
I use it for my servers to notify me about various events that you would normally use something like sendmail for. Two examples is that rTorrent sends me message when it has finished downloading a new torrent, which is handy since it automatically downloads torrents from a local folder that I share via the network and I don’t always have the session with rTorrent open to check its progress.
The other example is that it send the regular reports from Logwatch via XMPP, which is something I used to do via sendmail.
And here’s how it works:
$ echo "Hello world" | /usr/bin/site_perl/sendxmpp --tls-ca-path="/etc/ssl/certs" -t email@example.com
$ echo "Hello world" | /usr/bin/sendxmpp --tls-ca-path="/etc/ssl/certs" -t firstname.lastname@example.org
I had issues with some Bash script when I didn’t specify the static path to be binary on both my Arch Linux and Debian machines, which is why I use the full path. I also had to use the flag
--tls-ca-path="/etc/ssl/certs" for it to work with TLS.
The rTorrent script
The script for rTorrent looks like this:
#!/bin/bash echo -e "New torrent!\n\n$1" | /usr/bin/sendxmpp --tls-ca-path="/etc/ssl/certs" -t email@example.com
And in my
$HOME/.rtorrent.rc I added this:
method.set_key = event.download.finished,notify_xmpp,"execute2=/home/johan/Scripts/rtorrent-xmpp.sh,$d.name="
It’s available in the official repositories for Debian and Gentoo Linux as
net-im/sendxmpp. If you’re running Arch Linux you need to turn to the AUR; sendxmpp and sendxmpp-git.
The configuration file is
$HOME/.sendxmpprc and my configurations looks like this:
username: hund jserver: example.tld:5222 component: example.tld password: ***
And don’t forget to set some stricter permissions for the configuration:
$ chmod 600 ~/.sendxmpprc
That should be all. :)
A big thanks to vanad.is and the blog post “Send system cronjob output via XMPP”. It’s where I found out about this neat client.