From owner-freebsd-questions@FreeBSD.ORG Thu Aug 21 17:11:53 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 4AB3F16A4BF for ; Thu, 21 Aug 2003 17:11:53 -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 96FAB43FCB for ; Thu, 21 Aug 2003 17:11:52 -0700 (PDT) (envelope-from oremanj@webserver.get-linux.org) Received: (qmail 18678 invoked by uid 1000); 22 Aug 2003 00:11:51 -0000 Date: Thu, 21 Aug 2003 17:11:51 -0700 From: Joshua Oreman To: Walter Message-ID: <20030822001151.GA18619@webserver> References: <3F44F508.3020704@earthlink.net> <20030821165908.GB10811@webserver> <3F455A72.2050607@earthlink.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3F455A72.2050607@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: Fri, 22 Aug 2003 00:11:53 -0000 On Thu, Aug 21, 2003 at 06:49:06PM -0500 or thereabouts, Walter wrote: > Josh, > > Sorry to bother you, but the $RANDOM symbol returns > a blank. Do I need to initialize something? On bash/zsh $RANDOM returns a random number. On sh it's apparently undefined. To define it, do RANDOM=$( perl -e 'srand; print int(rand()*100000)%32767' ) > OTOH, > is there a shell command to extract the day of the > month from the string returned by 'date'? I think > now I'd prefer to do that. To do that (if you don't have enough files in the directory it will wrap around), do: DIR=<<< the directory >>> nfiles=$(ls -1 $DIR | wc -l | tr -d ' ') fileno=$(( ($(date +%d) % $nfiles) + 1) FILE=$DIR/$(ls -1 $DIR | head -n $fileno | tail -n 1) (The command is "date +%d"). -- Josh > > Thanks. > > Walter > > Joshua Oreman wrote: > > >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 > >> > >>___________