Re: Over-thinking find and mv - need a nudge

Brian Dunbar <[email protected]>
Newsgroups gmane.os.solaris.managers
Message-ID <[email protected]>
I got some coffee, walked around, and _thought_ about it.

I've got the originating directory - see below.  Writing to disk is probably
not the _best_ way but disk is cheap and fast, now.

Of course this concats all of the source files into one big file on
destination.  More coffee ...

function move_file
{
for D in `cat ${DIRECTORY_LIST}`
do
   log " ${D} files -> ${DESTINATION}"  >> $LOGFILE 2>&1
   echo ${D} > ${ORIGDIR}
   cat ${ORIGDIR}  #sanity check for dev
   ORIGDIR2=`awk 'BEGIN { FS = "/" } ; { print $NF }' ${D} ${ORIGDIR}`
   echo ${ORIGDIR2} #sanity check for dev
   sleep 3   # bash executes way too fast on my laptop - slow the heck down
   find ${D} -type f -maxdepth 1 \! -newer ${TIMER} -print  -exec mv -v "{}"
${DESTINATION}${ORIGDIR2}-${NOW} \;
done
}



On Mar 29, 2012, at 10:10 AM, Brian Dunbar wrote:

> 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]
> _______________________________________________
> sunmanagers mailing list
> [email protected]
> http://www.sunmanagers.org/mailman/listinfo/sunmanagers


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.