Over-thinking find and mv - need a nudge

Brian Dunbar <[email protected]>
Newsgroups gmane.os.solaris.managers
Message-ID <[email protected]>
Hi,

I've got what should be a simple task, but I think I'm over-thinking [1] the
solution.

Got a Solaris 10 host, lots of files, lots of users, inbound by FTP.  End user
wants them consolidated to a single directory.

Given a directory, with sub-directories.
I'm to move files older than 15 minutes to a single directory.
I can act on most of the directories, but not all of them.
Renamed files are to be in format
$source_directory$date-time$original_file_name

So that ...

/foo/file1.txt > /composite/foo-20120329-file.txt


Solaris, so I reached for my handy perl one-linerish to roll back the time so
find -newer works.

Here is what I've got so far.

Moves files to $DESTINATION, fine.

What I can't seem to figure out is a smooth way to obtain the originating
directory and file into variables so I can 'mv' them.

I may be - I am - missing something fundamental.  Or obvious.

Not committed to BASH, of course.

# directory.txt
/users/bdunbar/foo/test/d1
/users/bdunbar/foo/test/d2
/users/bdunbar/foo/test/d3

# script.sh
DIRECTORY_LIST=directory.txt
DESTINATION="/users/bdunbar/foo/composite"
NOW=$(date +"%Y-%m-%d-%H%M-%S")
TIMER="timer.txt"

for D in `cat ${DIRECTORY_LIST}`
do
   find ${D} -type f -maxdepth 1 \! -newer ${TIMER} -print  -exec mv -v "{}"
${DESTINATION} \;
done


[1] I may be over-thinking the over-thinking .. recursive gumption trap!

--


Brian Dunbar
Systems Administrator

Plexus Corporation
Desk: (920) 751-3364
Cell: (920) 716-2027
email: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.