ejes consulting

Techincal Consulting Design and Automation


with 6 comments

#!/usr/local/bin/bash -x

PATH=/bin:/sbin:/usr/bin:/usr/local/bin; export PATH;
DIR=$(xml sel -T -t -v “/freenas/bittorrent/configdir” /conf/config.xml)

cd ${DIR}blocklists/

LSIZE=$(stat -x $FILE | awk /”Size”/'{split($0,a,”Size: “);split(a[2],a,” “);print a[1];exit}’)
RSIZE=$(fetch -aspw 5 $URL)

# If there is a new version of the blocklist, download, extract, restart transmission & delete extracted file
if [ “$RSIZE” != “$LSIZE” ] && [ -n “$RSIZE” ] && [ “$RSIZE” -gt 0 ]; then
  fetch -apw 5 $URL
  gzip -dfkq $FILE
  echo “Blocklists updated on: $(date)” >> ${DIR}transmission_blocklists.log
  $INIT restart
  while [ -z $(pgrep transmission) ];do sleep 1;done
  sleep 10
  rm -f ${FILE%.*};

Written by ejes

July 20, 2009 at 10:00 am

6 Responses

Subscribe to comments with RSS.

  1. this script no longer works with the latest freenas.

    /conf/config.xml is not readable to the transmission user

    init.sh either no longer exists or it is in another location (that I could not find)


    June 8, 2010 at 3:06 am

    • What version are you running?


      June 8, 2010 at 8:54 am

  2. #!/usr/local/bin/bash -x

    PATH=/bin:/sbin:/usr/bin:/usr/local/bin; export PATH;

    cd ${DIR}blocklists/

    # Get local file size
    LocalSize=`stat -qf %z ${URL##*/}`

    # Get remote file size or exit
    logger -t Transmission Checking for new blocklist
    RemoteSize=`fetch -apsw 5 ${URL} || exit 1;`

    # If local file size not equal to remote file size update blocklist
    if [ ${LocalSize:-0} -ne ${RemoteSize} ]; then
    fetch -apw 5 $URL && \
    gzip -dfkq ${URL##*/} && \
    echo “Update found and downloaded”
    /etc/rc.d/transmission restart
    logger -t Transmission Updated blocklist
    echo “No update available now: `date`”
    logger -t Transmission No update available
    exit 0


    June 8, 2010 at 3:11 am

    • I modified the script so that it wont download the level1.gz to the blocklists directory since transmission tries to read anything with the level1 file name. http://pastebin.com/Bm1uE7ms


      August 28, 2010 at 12:47 am

  3. also, I could not copy-paste your above script. the character formating is not UTF8, it is ANSI.

    I tried many browsers and np++ notpade.exe and such.

    thank-you for your help, however, I just wanted to make mention of the above for the benefit of other users experiencing simmilar problems.



    June 8, 2010 at 3:13 am

    • Thanks Shaun, you’re correct it is ASCII.


      June 8, 2010 at 8:55 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: