Basic "scripting" (batch file?) question

Mark T. Valites yellowdog-general@lists.terrasoftsolutions.com
Wed May 22 11:44:01 2002


> (a) creates a folder with a "unique" name (generated by the batch file --
> e.g. date+time or random numbers, etc.)
>
> and then
>
> (b) moves files from one (permanent) directory to this (less permanent)
> directory.
>
> I used to be able to write simple "batch" files in mach Unix aeons (94) ago
> and make them executable (chmod -x?) but haven't been able to figure it out
> here (plus, I'd like to remap ls to my execute my own preferred -a and -L).
>
> First of all:
> (1) how would I generate a unique name (e.g. date+time)
> (2) how would I get that name (uniquename) to be used in the "mkdir
> uniquename" and "mv /Permanent/* /uniquename/" commands
> (3) how would I make that file "executable" (I thought it was chmod -x or -X
> but that doesn't seem to work).
>

in bash, $RANDOM is a good start.  There are plenty of random functions in
perl if you'd like to go that route.

#!/bin/bash

DATE=`date | some_formatting_here` # (or something like date -u +%a)
# the things within the back-ticks get evaluated & a value returned
OLD_FOLDER=~already_exists
NEW_FOLDER=temp.$RANDOM
mkdir ~$NEW_FOLDER
mkdir ~$DATE
mv $OLD_FOLDER/* NEW_FOLDER/

chmod +x, not -x!!  Probably drove you crazy!  "-" takes the executable
bit away.


>--))> >--))>
Mark T. Valites
Unix Systems Analyst
1 College Circle - 124b1 South Hall
SUNY Geneseo
Geneseo, NY 14454
585-245-5577
585-259-3471 (Cell)