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:

Arch Linux:

$ echo "Hello world" | /usr/bin/site_perl/sendxmpp --tls-ca-path="/etc/ssl/certs" -t hund@example.tld

Debian:

$ echo "Hello world" | /usr/bin/sendxmpp --tls-ca-path="/etc/ssl/certs" -t hund@example.tld

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 hund@example.tld

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="

Installation

It’s available in the official repositories for Debian and Gentoo Linux as sendxmpp and net-im/sendxmpp. If you’re running Arch Linux you need to turn to the AUR; sendxmpp and sendxmpp-git.

Configuration

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. :)

Credits

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.

Comments

I'm looking into a good way of implementing comments on my blog that works without JavaScript, respects the users privacy and is reasonably user friendly. If you have any ideas or just want to give me some feedback on this blog post or if you just want to say hello, feel free to do so either via e-mail, XMPP or Mastodon.