Re: [Hampshire] Cron script spawning too many programs?

Top Page

Reply to this message
Author: Steve Kemp
Date:  
To: Hampshire LUG Discussion List
Subject: Re: [Hampshire] Cron script spawning too many programs?
On Wed Mar 04, 2009 at 20:37:57 +0000, AdamC wrote:

> Can anyone think of a reason why when cron executes a script many more
> programs start (at least over 5), but when I run the script from a
> shell, I get the correct amount of programs running that I am
> expecting?


1. Cron runs.

1a. Cronjob finds *.torrent
1b. btdownloadcurses starts for each file.

2. Cron runs. Again - goto 1a.

Solution? Make sure that you only start once for each file. Maybe
something like this:

(Notice I've removed the $(ls ..) seems redundant )

#!/bin/sh
# start in correct dir
cd /home/skx/torrents/spool

# find *.torrent
for i in *.torrent; do

    # if not already running start up
    if [ ! -e $i.working ]; then


        #create marker so this file is ignored by
        # next run of cron
        touch $i.working


        # download
        /usr/bin/btdownloadcurses $i > /dev/null &
    fi
done


Steve
--
Stop blog&forum spam
http://blogspam.net/