Changes between Initial Version and Version 1 of Scripts/Watchdog


Ignore:
Timestamp:
Dec 15, 2008, 9:45:54 AM (13 years ago)
Author:
Waldorf
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Scripts/Watchdog

    v1 v1  
     1= Watch Directory Script =
     2== Notes ==
     3To run this script at an interval, add this to your crontab.
     4
     5== Script "watchdog.sh" ==
     6{{{
     7#!/bin/bash
     8#
     9
     10# Authentication "username:password"
     11#tr_auth="admin:admin"
     12
     13# Watch dir, may contain spaces:
     14watchdir="/torrentwatch/"
     15
     16# move file to a subdirectory? if Commented out, it'll be removed.
     17# *Don't put a '/' before the path*
     18movesubdir="added/"
     19
     20# Verbose?
     21verbose=1
     22
     23for file in "$watchdir"*.torrent
     24do
     25    if [ -f "$file" ]; then
     26        if [ $verbose ]; then echo "$file added to queue."; fi
     27    else
     28        if [ $verbose ]; then echo "No torrent in $watchdir."; fi
     29
     30        if [ $tr_auth ]; then
     31            /usr/bin/transmission-remote --auth="$tr_auth" -a "$file"
     32        else
     33            /usr/bin/transmission-remote -a "$file"
     34        fi
     35       
     36        # give the remote some time to process
     37        sleep 5
     38       
     39        if [ $movesubdir ]; then
     40            if [ -d "$watchdir$movesubdir" ]; then
     41                mv "$file" "$watchDir$movesubdir"
     42            else
     43                mkdir "$watchdir$movesubdir"
     44                mv "$file" "$watchdir$movesubdir"
     45            fi
     46        else
     47            rm "$file"
     48        fi
     49    fi
     50done
     51
     52exit 0
     53}}}