Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Aug 2003 09:59:08 -0700
From:      Joshua Oreman <oremanj@get-linux.org>
To:        Walter <walterk1@earthlink.net>
Cc:        questions@freebsd.org
Subject:   Re: file picker
Message-ID:  <20030821165908.GB10811@webserver>
In-Reply-To: <3F44F508.3020704@earthlink.net>
References:  <3F44F508.3020704@earthlink.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Aug 21, 2003 at 11:36:24AM -0500 or thereabouts, Walter wrote:
> Hi All,
> 
>    I want to run a cron job to upload a different image
> file to a web site as a new background every night.
> 
>    I need a way to automatically select a different file
> from a directory which I will populate over time, and
> then feed that name to the upload script.  I can't find
> anything like this in the ports.  Can someone suggest
> a utility, script, et cetera, for this?  Otherwise, I'm
> prepared to write my own, but I don't want to re-invent
> the wheel, as the saying goes.  Thanks.


To select a random file from the directory, try this:-

DIR=<<< the directory >>>
nfiles=$(ls -1 $DIR | wc -l | tr -d ' ')
fileno=$(( ($RANDOM % $nfiles) + 1 ))
FILE=$DIR/$(ls -1 $DIR | head -n $fileno | tail -n 1)

# $FILE now contains the full pathname of the file to
# upload. I'm sure you can handle the upload task :-)
#
# Note: this script may re-use the same file later. To
# prevent this, add a line below the upload:
#  mv $FILE /somewhere/else/
# That way the directory will only contain unused files.

-- Josh

> 
>    Please CC me as I'm not currently subscribed to the
> List.
> 
> Walter
> 
> _______________________________________________
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030821165908.GB10811>