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 > >> > >>___________ _______________________________________________ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"