tfnotify: A notification script for Torrentflux 2.4
Torrentflux is a really slick torrent app that revolves around a php based web gui. It allows for multiple torrents, queueing, and pretty much any of the standard fare of options you would get with a command line torrent client. The one thing that it was missing in my mind was some form of notification. I went ahead and wrote a shellscript that notifies you via email upon a torrents completion. Its fairly straight forward and has very few requirements. The sendEmail script it employs does require a few perl modules, but they are readily available and simple to install. For us ubuntutor users they are available via apt and easy to find using synaptic. Essentially all you should need are a working cron daemon (available on most *unix; this was written with the standard vixie cron in mind and might need slight modification for other cron daemons), perl, and sed. The configuration is all managed in the script it self with a list of commented variables that need to be filled in.
The script works simply by using the user crontab to run itself once each minute, notifying when necessary. My favorite use is with my cellphone's email address so i can get a text when my torrents finish. The download link is available below. If you have any questions or problems feel free to leave a comment and i will get back to you.
Getting the most out of the terminal with gnu screen
For a long time screen was just that program you used to leave stuff running after you log off. It wasn't until recently that i realized it was oh such more. It is a power user's best friend. The most useful thing is when connecting to a remote server. While maintaining just one connection you can be easily switching between a multitude of terminals. Also for long unattended script or program runs with a large scrollback buffer and copy mode its easy to check on whats been going on, or even make a hardcopy to grep through at your leisure.
I am just going to go ahead and break down how i have screen setup. The first thing is to use a proper .screenrc . I found that to get the most out of screen i wanted to be able to see how many screens i had and which one i was in. In addition i wanted a large scroll back, and to ditch that stupid splash screen. Here is the .screenrc i came up with ( none of which was originally written by me ).
altscreen on
hardstatus on
hardstatus alwayslastline
hardstatus string "%= %3n %t%? [%h]%? %="
caption always
caption string "%= %-w%L>%{= BW}%n*%t%{-}%52<%+w %L="
defscrollback 30000
startup_message off
When starting up screen i would go ahead and use the -S option and give it a name i.e. screen -S transfers so that if you decide to open a separate screen ( for some silly reason ) then they will be easier to manage. Also if you plan on having multiple screens inside give this tab a name with the -t option i.e. screen -S transfers -t backups . When you want to open further tabs just type screen -t tabname from within the screen.
Navigating the different tabs can seem tricky at first, but becomes second nature quite quickly. Screen uses a two part command system. so you hit the first key combination then the second. Screen has lots of commands that are better explained elsewhere (man screen) but here are the select few i use day in and out.
ctrl+a - n : next tab ctrl+a - K : kill tab ctrl+a - c : create tab ctrl+a - # : go to screen # ctrl+a - [ : go into copy mode. allows you to scroll into the scrollback buffer using pageup and pagedown ctrl+a - backspace : prev tab ctrl+a - h : create a hardcopy of the current screen buffer ctrl+a - A : set windows title ctrl+a - d : detach of course. screen -r to reattach to it. screen -r SCREENNAME if you have many screens.
With this you will be zipping through screens all the time in no time.
How to retain variables out of a sub shell in bash.
A while back I was writing a BASH script that was processing folders full of files into an array to be transferred. The best method i found to do this was to use find and pipe it to a while read loop for processing. While this sounded good in theory i had created a small problem for myself. I was now stuck within the confines of a sub-shell, and any array i built would evaporate upon its completion. Well how to get this array out of this sub-shell. BASH itself does not provide a ready solution to this but I came up with a trick to do it using the declare command. Here is a snippet of the script in question:
filenamearray="$(find "$folder" | sort | while read file
do
if [ -f "$file" ]
then
echo "$file"
fi
done | ( while read line
do
filename[${#filename[@]}]="$line"
done
declare -a | grep "filename"
))"
eval "$filenamearray"
The declare command when passed the -a option will list declare statements for all currently declared variables. By grep'ing out our array and placing the declare statement that defines it into the filenamearray variable, we are then able to eval it and recreate it in our current shell so it can be used during the rest of the script. The example is some what more than is really needed but I already had it written
.
Well I hope this helps somebody.


