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.
> Please CC me as I'm not currently subscribed to the
> [EMAIL PROTECTED] mailing list
> To unsubscribe, send any mail to "[EMAIL PROTECTED]"
[EMAIL PROTECTED] mailing list
To unsubscribe, send any mail to "[EMAIL PROTECTED]"