Re: Find and I need help (95 Views)
Reply
Occasional Visitor
Willial P. J. Bressette
Posts: 1
Registered: ‎08-02-1999
Message 1 of 9 (95 Views)

Find and I need help

Greetings all

hear is what I'm trying to do, creat a scripts that moves any files what are
more than 7 days old to a history dir

hear is my script.

NDAYS="7"
ARDIR="/u/if/archive"
HSDIR="/u/if/history"
find $ARDIR -xdev -type f -mtime +$DAYS -exec mv {} $HSDIR \;

end of scripts

could someone tell me what i did wronf with find.

cause the only thing it moved the files but it takes the file out of the
archive dir and then moves it to /u/if with the file name of history ???? whats
up with that.....

thanx

william
Please use plain text.
Occasional Visitor
mary_76
Posts: 1
Registered: ‎08-18-1999
Message 2 of 9 (95 Views)

Re: Find and I need help

try the following change
HSDIR="/u/if/history/"
Please use plain text.
Occasional Visitor
a unix person
Posts: 2
Registered: ‎08-26-1999
Message 3 of 9 (95 Views)

Re: Find and I need help

quote the variables thus ${varname}
the mv will then execute successfully
Please use plain text.
Occasional Visitor
William_198
Posts: 4
Registered: ‎08-31-1999
Message 4 of 9 (95 Views)

Re: Find and I need help

The Vars that you want me to quote with {} is that the var on the command line
or when i set them??

william
Please use plain text.
Occasional Visitor
William_198
Posts: 4
Registered: ‎08-31-1999
Message 5 of 9 (95 Views)

Re: Find and I need help

Mary,

I had tried this aswell and i ened up with the same results

thanx thou

william
Please use plain text.
Occasional Visitor
Pawel Wozniak
Posts: 1
Registered: ‎09-01-1999
Message 6 of 9 (95 Views)

Re: Find and I need help

Hi

I think that directory pointed by $HISDIR
did not exist when you run he script for the first time.
So mv treated $HISDIR as target file to be created.
And repeated the same for each found file.

You need to:
1. delete file, now pointed by $HISDIR
2. create directory pointed by $HISDIR
3. run the script again

I guess it helps.

Pawel
Please use plain text.
Occasional Visitor
William_198
Posts: 4
Registered: ‎08-31-1999
Message 7 of 9 (95 Views)

Re: Find and I need help

Greetings, nope, i did have the dir created that is what stumps
me,.....interesting

william

PS does anyone know a good HP-UX book on scripts and sercrets etc???

william
Please use plain text.
Occasional Visitor
David Blankenship
Posts: 1
Registered: ‎10-21-1999
Message 8 of 9 (95 Views)

Re: Find and I need help

The best shell programming book I have found is

Hands-On KornShell93 Programming by Barry Rosenberg.

I like this book because it has many many examples and it explains why certian
commands should no longer be used.

I found this book at Borders for around $45.

Take a look at it and see if it fits your needs.
Please use plain text.
Regular Advisor
Alan Riggs_1
Posts: 100
Registered: ‎10-21-1999
Message 9 of 9 (95 Views)

Re: Find and I need help

If the directory from which you are moving files is flat, then you can make the
mv command work by properly bracing the variable names in the find command:

find ${DIR} -type f -exec mv {} ${NEW_DIR} \;

However, this will flatten any subdirectories under your original structure.
To preserve them, I have used a two-stage process in the past:

DIR=/tmp/archive
TARG=/tmp/history
cd $DIR
find . -type f |cpio -pdumx ${TARG}
find . -type f -exec rm {} \;

And, yes, I know there is a cpio flag on find, but I have experienced
unexpected results from it in the past and prefer the flexibility and control
of the real thing. There is probably a more elegant way to do this, but this
works.
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation