LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 11-20-2008, 05:26 PM   #1
ddenton
Member
 
Registered: May 2007
Posts: 114

Rep: Reputation: 15
Shell Scripting Question (mv via find/-exec)


Hello.

I have a shell script whose purpose is to move images from one location to another to save space. It's supposed to find any image directory in a tree of parent directories and move any image folder older than 180 days.

The issue I'm having is that for the first subfolder (coincidentally the oldest) to be moved, somehow only the files in that directory are moved to their target location, leaving loose files that should be in their own folder.

Next is the script:

Code:
#!/bin/sh

# Set blacklist variables...
BL="/usr/local/imagetest/XXXXXX"

for CID in /usr/local/imagetest/??????; do

if [ -d "$CID" ] && [[ `echo $BL | grep -v $CID` ]];
        then
        cd $CID
        date >> /usr/local/imagetest/purgelist.log
        CIDDIR=`pwd | awk -F / '{print $4}'`
        echo $CIDDIR >> /usr/local/imagetest/purgelist.log
        find . -type d -mtime +180 -exec mv {} /usr/local/imagetest/retired_images/$CIDDIR/ \; # >> /usr/local/imagetest/purgelist.log
        else
        echo "$CID is in the blacklist. Ignore." >> /usr/local/imagetest/purgelist.log
fi
done

echo "Purge process complete for `date +%F`." >> /usr/local/imagetest/purgelist.log
And here's output of the script, and a file listing for the target location:

Code:
find: ./20080423: No such file or directory
find: ./20080501: No such file or directory
find: ./20080505: No such file or directory
find: ./20080506: No such file or directory
find: ./20080507: No such file or directory
find: ./20080508: No such file or directory
find: ./20080509: No such file or directory
find: ./20080512: No such file or directory
find: ./20080513: No such file or directory
find: ./20080514: No such file or directory
find: ./20080515: No such file or directory
find: ./20080520: No such file or directory
And...

Code:
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080501
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080505
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080506
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080507
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080508
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080509
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080512
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080513
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080514
drwxr-xr-x  2 root root  4096 Nov 20 17:11 20080515
drwxr-xr-x  2 root root  8192 Nov 20 17:11 20080520
-rw-r--r--  1 root root 11840 Apr 23  2008 file1.tif
-rw-r--r--  1 root root  1430 Apr 23  2008 file2.tif
-rw-r--r--  1 root root 10608 Apr 23  2008 file3.tif
-rw-r--r--  1 root root   301 Apr 23  2008 file4.tif
So can anyone tell me why the 20080423 directory wasn't re-created whole during the move? The files should be in their own directory. I'm sure it's some stupid quirk with using move with find -exec, but I'd like a solid answer.

Also, yes, I know the error output can be piped to /dev/null, but in this case it helped. Thanks!
 
Old 11-21-2008, 07:54 AM   #2
ddenton
Member
 
Registered: May 2007
Posts: 114

Original Poster
Rep: Reputation: 15
Any input would be greatly appreciated...
 
Old 11-21-2008, 08:02 AM   #3
ddenton
Member
 
Registered: May 2007
Posts: 114

Original Poster
Rep: Reputation: 15
I think I've found the solution. Since the first subdir to be copied was the one that wasn't recreated properly, I assumed that subdir's parent directory had not yet finished being created. By inserting a statement before the find command to create the subdir's parent directory using the same CIDDIR variable in the find command, the "-exec mv" created all of the subdirs correctly.
 
Old 11-21-2008, 08:10 AM   #4
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,281

Rep: Reputation: 802Reputation: 802Reputation: 802Reputation: 802Reputation: 802Reputation: 802Reputation: 802
Perhaps the 20080423 directory has been modified in the last 180 days?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Why Non-Technical Users Might Find Shell Scripting Useful LXer Syndicated Linux News 0 10-31-2007 10:50 AM
Assistance with 'find -exec cp' shell script dick.swift Linux - Software 6 01-23-2006 10:00 AM
Shell scripting to find length of filenames ridertech Linux - Newbie 2 08-25-2004 12:07 PM
find -exec question eantoranz Linux - General 1 06-26-2004 10:57 AM
Where to find about shell scripting in the internet green_one Linux - Software 3 04-23-2004 05:33 PM


All times are GMT -5. The time now is 04:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration