Posts Tagged ‘sendxmpp’

Important Dates Notifier

Saturday, January 29th, 2011

I have never been especially good at remembering dates or appointments. My memory just doesn’t seem constructed to handle things like “on YYYY-MM-DD do X” (peculiarly enough, “on Friday next week, have X done” works much better).

I guess things relative to “now” works better for me (at least in the short term) than some abstract date some time into the future.

Luckily enough, I don’t seem to be the only one suffering from having an “appointment-impaired memory” so others have created calendar applications and what not.

These work great, the one I presently use, remind is awesome. But sometimes it isn’t “intrusive” enough.

There are some appointments/dates that are important enough that I would like for remind to hunt me down an alley and smack me over the head with the notification, as opposed to presenting it to me when I query it for today’s appointments.

So I put together a little shell script which push notifications (the ones I feel are the most important) to me via jabber.

The solution involves cron, remind, grep and a nifty little program called sendxmpp.

This script I have placed on my “laptop-made-server” which coincidentally also happens to be the central mercurial server, through which I synchronize the repositories on my desktop and netbook.

Which means that if I just take care to clone the specific repository containing my remind files to some place local on the server, I could have a cronjob pull and update that repository and it would thus always (as long as I have pushed changes made from the desktop/netbook) have the most up to date files available.

If setting up a repository server seems to big of a hassle, one could of course (at least with remind) have a master ~/.reminders file, which then invokes an INCLUDE expression.

This makes remind look in the specified directory for other files, and in that directory have one file for each computer (along the lines of .rem) and have each individual machine scp (and overwrite) their individual file every now and then.

In any case, once the server have fresh and updated sources of data, all it need do is execute the idn.sh script once every day (preferably early, this will work pretty well as the jabber-server I use caches all messages sent to me while I was offline, so once I log in again, I’ll get the notifications then).

As sendxmpp takes the message from STDIN, recipient-addresses as parameters, and parses a configuration file to divine what account should be used to send the message (I set up a “bot” account to send from, and then just authorized that bot in my primary jabber-account), I see no reason why someone couldn’t modify the script to instead (or in addition) use something like msmtp to send out and email instead.

The script itself, in its current form, is rather straightforward, although I’m sure there are still room for optimizations.

#!/bin/sh
TAGS="#Birthday #ATTENTION"

for t in `echo "$TAGS"`;
do
    rem | grep -i "$t" | while read line;
    do
        echo "$line" | sendxmpp recipient@jabber.example.org
    done
done
exit 0

Relevant parts of my crontab:

0   7   *   *   *       cd /home/patrik/remind-repo; /usr/bin/hg pull -u 2>&1
5   7   *   *   *       cd /home/patrik/idn-repo; /usr/bin/hg pull -u 2>&1
10  7   *   *   *       /bin/bash /home/patrik/bin/idn.sh 2>&1

In /home/patrik I have created symlinks /home/patrik/.remind -> /home/patrik/remind-repo/.remind and /home/patrik/.reminders -> /home/patrik/remind-repo/.reminders

And in /home/patrik/bin/ I have a symlink (idn.sh) to /home/patrik/idn-repo/idn.sh. So in case I change the script, like add a tag to look for or something (ok, that should be moved out to a configuration file, that will be part of the next version) that will be picked up as well, before the notifications goes out.

And that’s about it. Risk of forgetting something important: mitigated.

:wq

My software stack revisited – Server

Tuesday, December 28th, 2010

The addition of the server (in my case, an old laptop onto which I installed Ubuntu server) has made a rather substantial difference on how I work.

While I don’t have any love or trust for the cloud when operated by others, deploying my own miniature cloud is something different altogether. The difference being that in my setup, the data is under my control, and as long as I don’t screw the security settings up, the data is only available to me and the ones I grant access.

Repositories

Mercurial, albeit being a distributed version control system, can be made centralized. It is simple. You just set up all your repositories on a computer, and make it easy to clone, pull and push from and to that computer.

The mercurial-server package does just that, by providing an SSH interface over which people who are authorized (mercurial-server uses SSH keys) can then access the repositories, based on rules in an access configuration file.

All my small projects are now under version control, along with the configuration-files of both my desktop and my netbook.

RSS

In a comment on my original post, archie asked me about how I consume RSS feeds. The answer now is the same as back then: “Thunderbird.”

Back then using Thunderbird for that was a hassle: I had it installed on two computers, my desktop and my laptop, and I’d set both up to fetch the same feeds, which either of the Thunderbird instances would only do if the computer was powered up and Thunderbird was running.

That meant I’d sometimes miss posts in feeds that were aggregating feeds themselves. But what was even more frustrating was when both computers fetched the same feed items, and after having read it in one place, I would then need to prune it from the other location.

Sometime near the end of my time at ITU, pesa made me see the light of IMAP, that mails are stored on the server, and marked as either read or unread. And that any other client connecting in to the same account, would see the emails with the state the first client had left them in.

And I began thinking that it would be awesome to have that for RSS as well. Then there would be no problems synchronizing the feeds, because they’d all be in one place, and no matter which computer I was sitting at, it would have the most updated state.

Also, putting this on a central server would ensure that I wouldn’t miss any posts due to powering down either the laptop or the desktop.

After a bit of searching I found what I was looking for: feed2imap. It polls the feeds specified in the configuration file, at regular intervals as defined in the crontab which executes the feed2imap script, and then converts everything new it finds into the funky mail format hokus pokus which I have yet to fully grasp, putting the output in a Maildir.

Having done that, I would then need an IMAP capable mail-server to serve said mails (feed items) to me, and this is where Dovecot comes into play. With these two components, I can continue using Thunderbird (any IMAP-capable mail-reader actually) to consume my feeds, but in a much better way.

Screen

Another advantage of running a server is that it is supposed to be up and kicking and online, all of the time, and with the remarkable little software GNU Screen one could for instance start irssi (any CLI-application really) in screen, and then attach and detach it and have it live on until you decide to shut the application down. This means that you can have irssi stay online and thus get full access to what is happening in the various channels, even if you yourself are sleeping, or have shut down the work-computer for the day and are on your way home.

Access

The above services I run on the server, with the exception of the “RSS service”, require access to the system via some secure means (SSH), so openssh-server is installed. I have disallowed all password-based authentication, which leaves key-based authentication the only viable option.

However, sometimes one might need access to the server but either don’t have the SSH private key with you (USB-stick) or don’t feel comfortable using / unlocking it from the computer you are currently sitting at.

This is where OPIE comes into play. My cellphone can run Java, so I installed a program called OTPGen on it, which generate the response to an OPIE challenge as sent from the server.

Which basically means that I can log in to the server and any password sniffer can just suck it, because that password I just used is now useless.

Notifications

In part six I wrote about calendars, about appointments, and more specifically about when and remind. In part three I wrote about version control. About mercurial. And in the beginning of this post I wrote about how this server hosts repositories, not just projects, source code etc, but also configurations. Configurations such as the appointment files for when and remind.

In Ubuntus repositories (and in Archlinux AUR) there lies a little package named sendxmpp, with which one can send messages.

I put together a little service of my own, using crontab, a shell script, and sendxmpp. Every morning it pulls updates from the repository, runs when (I haven’t gotten around to updating the script to use remind yet) and parses the output, and if any messages with a specific tag (most notably #Birthday) is found in the filtered output, send that to my primary jabber-account through sendxmpp.

We’re nearly at the end now. Just a final post to summarize and glance forward left in this series.

:wq