rtorrent: Receiving an email when a download is complete
Since I had to get the information from different websites, I thought I would make a post compiling all the info necessary.
I’m using rtorrent on a remote server (running Ubuntu) and I wanted to receive a mail when rtorrent is done downloading a file, so that I wouldn’t have to check it by hand. I still have to download the files manually but that will be my next assignment!
First things first, you need a valid email address from which you will send these notifications. I created a gmail email address because it was the most convenient solution at the time. Let’s call it email@example.com and let’s say I wasn’t really concerned with security and used ‘qwerty’ as a password.
Next, you’ll need to install and configure a package to send email from the terminal. I’ve adapted this guide, which helped me greatly, to Debian based distros.
Install ssmtp with something like: sudo apt-get install ssmtp
Configure it by editing /etc/ssmtp/ssmtp.conf and change it to:
firstname.lastname@example.org mailhub=smtp.gmail.com:587 rewriteDomain= hostname=smtp.gmail.com:587 UseSTARTTLS=YES UseTLS=YES AuthUser=mybox AuthPass=qwerty AuthMethod=LOGIN
And in /etc/ssmtp/revaliases:
Obviously, change the fields to match your own login credentials.
To test your configuration try this: echo test | mail -s "Hey this actually works!" email@example.com
You should receive a mail from firstname.lastname@example.org. For more details on the mail command, see the man page.
Let’s now write a script that sends email to your personal address. Later on, we’ll tell rtorrent to execute this script when a download is completed.
Create a rtorrent_mail.sh file wherever you want and edit it like so:
#!/bin/sh echo "$(date) : $1 - Download completed." | mail -s "[rtorrent] - Download completed : $1" email@example.com
Don’t forget to make it executable (chmod +x rtorrent_mail.sh) and to give it the right permissions (the user launching rtorrent needs to be able to execute it).
Finally, we need to hook this script to rtorrent. In your .rtorrent.rc, add the following line:
system.method.set_key = event.download.finished,notify_me,"execute=/path/to/script/rtorrent_mail.sh,$d.get_name="
If I’m not mistaken, this hooks the notify_me receiver to the event.download.finished signal (or event). The last part between quotes is the content of the notify_me method.
Once again, put the path corresponding to where you put your script. You might need to restart rtorrent for these settings to be active.
Here you go! rtorrent will automatically send you emails when a download is completed.
This post doesn’t cover everything I did with rtorrent. I’m actually sharing my VPS with a very good friend of mine and we both get notified when a download is completed. This is great for tv shows we both watch. What if you want rtorrent to send an email to different users depending on the files it downloaded? (practical example: you don’t want your dear friend to know that you are very much into videos displaying women and horses in a lewd manner)
Well, that will be the object of a future post !