Hi
Would any coder out there be willing to make a version of the e-Mail Notification script that will send mail not when the download has reached 100% but when it has reached a given ratio value or when it has switched to "Stopped" status?
Thanks
email notification based on status or ratio
-
- Transmission Developer
- Posts: 3142
- Joined: Fri Jan 13, 2006 8:08 pm
Re: email notification based on status or ratio
I believe Growl on Mac can do this.
Re: email notification based on status or ratio
Well... I'm on Linux so Growl won't be of much help ...
Re: email notification based on status or ratio
The script author has been kind enough to send me a version that will send the notification mail only when status has switched to "Stopped".
That guy rocks
Here it is in case someone else is interested.
That guy rocks
Here it is in case someone else is interested.
Code: Select all
#!/bin/sh
# Script that checks for finished downloads in Transmission and
# sends email to a specified user.
# This code placed into public domain
# Requires:
# GNU mailutils | bsd-mailx (does not work with heirloom-mailx)
# lockfile-progs
# transmission-cli
# History:
#-------------+---------------------------------+-----------------------------+
# Date | Author <EMail> | Description |
#-------------+---------------------------------+-----------------------------+
# 04 May 2009 | A.Galanin <gaa.nnov AT mail.ru> | Creation |
#-------------+---------------------------------+-----------------------------+
# 04 May 2009 | A.Galanin <gaa.nnov AT mail.ru> | Usage moved before locking |
#-------------+---------------------------------+-----------------------------+
# 07 May 2009 | A.Galanin <gaa.nnov AT mail.ru> | Fixed exitAndClean call |
# | | in case when file locking |
# | | failed |
#-------------+---------------------------------+-----------------------------+
# 09 May 2009 | A.Galanin <gaa.nnov AT mail.ru> | Check for failures reported |
# | | by transmission-remote |
#-------------+---------------------------------+-----------------------------+
# 08 Jun 2009 | A.Galanin <gaa.nnov AT mail.ru> | More accurate error checking|
#-------------+---------------------------------+-----------------------------+
# 30 Jun 2009 | A.Galanin <gaa.nnov AT mail.ru> | More accurate error checking|
#-------------+---------------------------------+-----------------------------+
# $Id: checkFinishedTransmissionDownloads.sh,v f293989fbcd4 2009/07/11 19:49:34 gaa $
# default configuration options
# put it into config file ~/.checkFinishedTransmissionDownloads/config
HOST=localhost
PORT=9091
RPC_AUTH=1
USER=username
PASS=password
MAILTO=root
FROM=torrent-checker
MAIL_CONTENT="Downloading of \"%s\" has been finished.\nGo to %s to make an approriate action.\n"
#------------------------------------------------------------------------------
# files
FILEPATH="$HOME/.checkFinishedTransmissionDownloads"
CONFIG_FILE="$FILEPATH/config"
NOTIFY_FILE="$FILEPATH/notified"
ALL_FILE="/tmp/checkFinishedTransmissionDownloads.all"
TMP_FILE="/tmp/checkFinishedTransmissionDownloads.tmp"
TMP_FILE2="/tmp/checkFinishedTransmissionDownloads.tmp2"
LIST_FILE="/tmp/checkFinishedTransmissionDownloads.list"
ERR_FILE="/tmp/checkFinishedTransmissionDownloads.err"
LOCK_FILE="/tmp/checkFinishedTransmissionDownloads"
[ -f "$CONFIG_FILE" ] && . "$CONFIG_FILE"
#------------------------------------------------------------------------------
# Call transmission-remote with corresponding parameters
callTransmission () {
if [ "$RPC_AUTH" -eq 0 ]
then
transmission-remote "$HOST":"$PORT" "$@" 2> "$ERR_FILE"
else
transmission-remote "$HOST":"$PORT" -N "$TMP_FILE" "$@" 2> "$ERR_FILE"
fi
errSize="`ls -l "$ERR_FILE" | awk '{print $5}'`"
if [ "$errSize" -gt 0 ]
then
echo "Error while accessing Transmission daemon: " >&2
cat "$ERR_FILE" >&2
exitAndClean 3
fi
rm -f "$ERR_FILE"
}
# Remove lock and temporary files, exit with code $1
exitAndClean () {
[ -z "$LOCK_PID" ] || kill "$LOCK_PID"
lockfile-remove "$LOCK_FILE"
rm -f "$TMP_FILE" "$ALL_FILE" "$ERR_FILE" "$LIST_FILE" "$TMP_FILE2"
exit "$1"
}
# initialization
if [ $# != 0 ]
then
echo "$0: check for finished downloads in Transmission"
echo "USAGE: $0"
exit 1
fi
umask 077
lockfile-create "$LOCK_FILE" || (echo "Unable to lock lockfile!" >&2; exitAndClean 2)
lockfile-touch "$LOCK_FILE" &
LOCK_PID="$!"
MAIN_PID="$$"
trap "exitAndClean 1" HUP INT QUIT KILL
mkdir -p "$FILEPATH"
touch "$NOTIFY_FILE" "$TMP_FILE"
echo -n > "$ALL_FILE"
# generate netrc file for RPC authorisation
printf "machine %s\nlogin %s\npassword %s\n" "$HOST" "$USER" "$PASS" > "$TMP_FILE"
# main
callTransmission -l > "$TMP_FILE2" || exitAndClean 1
gawk '{
if ($1 != "Sum:" && $1 != "ID") {
print $1,$2
}
}' "$TMP_FILE2" > "$LIST_FILE"
while read id percent
do
id="`echo "$id" | sed 's/\*//'`"
reply="`callTransmission -t "$id" -i`"
[ $? -eq 0 ] || exitAndClean 1
name="`echo "$reply" | grep '^ Name' | cut -c 9-`"
hash="`echo "$reply" | grep '^ Hash' | cut -c 9-`"
error="`echo "$reply" | grep '^ Error' | cut -c 10-`"
state="`echo "$reply" | grep '^ State' | cut -c 10-`"
# check that notification is not yet sent
grep -q "$hash" "$NOTIFY_FILE"
if [ $? = 1 -a "$state" = "Stopped" ]
then
printf "$MAIL_CONTENT" "$name" "http://$HOST:$PORT/" | \
mailx $MAILTO -s "Torrents info: $name" -a "From: $FROM"
echo "$hash" >> "$NOTIFY_FILE"
fi
if [ -n "$error" ]
then
#print error message
echo "$name: $error"
fi
echo "$hash" >> "$ALL_FILE"
done < "$LIST_FILE"
# remove deleted torrents from sent notifications list
sort "$NOTIFY_FILE" > "$TMP_FILE"
mv "$TMP_FILE" "$TMP_FILE2"
sort "$ALL_FILE" > "$TMP_FILE"
mv "$TMP_FILE" "$ALL_FILE"
comm -1 -2 "$TMP_FILE2" "$ALL_FILE" > "$TMP_FILE"
mv "$TMP_FILE" "$NOTIFY_FILE"
exitAndClean 0