From owner-freebsd-questions@FreeBSD.ORG Thu Aug 21 09:59:10 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8FDDE16A4C1 for ; Thu, 21 Aug 2003 09:59:10 -0700 (PDT) Received: from webserver.get-linux.org (adsl-64-161-78-226.dsl.lsan03.pacbell.net [64.161.78.226]) by mx1.FreeBSD.org (Postfix) with SMTP id E6C0543F85 for ; Thu, 21 Aug 2003 09:59:09 -0700 (PDT) (envelope-from oremanj@webserver.get-linux.org) Received: (qmail 11890 invoked by uid 1000); 21 Aug 2003 16:59:08 -0000 Date: Thu, 21 Aug 2003 09:59:08 -0700 From: Joshua Oreman To: Walter Message-ID: <20030821165908.GB10811@webserver> References: <3F44F508.3020704@earthlink.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3F44F508.3020704@earthlink.net> User-Agent: Mutt/1.4.1i cc: questions@freebsd.org Subject: Re: file picker X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Aug 2003 16:59:10 -0000 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"