Find file extensions older than a month & com

Sun microsystems Sun fire v20z amd opter...
October 28, 2010 at 00:09:05
Specs: Linux Red Hat, 2gb/4gb
HI I have a script that will do this:

DATE=`date +%d%m%y`
OLDXML=`find /dir/docs/ -type f -name \*.xml -mtime +30 -print >/var/log/xmldel.log`
for i in `cat /var/log/xmldel.log`
tar cvzf /dir/docs/oldXML$DATE.tgz $i
rm -f $i
mail -s "OLD XML File's Archived on Test Server" </var/log/xmldel.log

I some how get some funny errors that files dont exsist or cannot stat etc.
Is there another way this can be done?


See More: Find file extensions older than a month & com

Report •

October 28, 2010 at 07:22:25
First, I am surprised that this works:

..... -type f -name \*.xml -mtime +30 ....

I would have done this:

.... -type f -name "*.xml" -mtime +30 ....

Second, My guess is that the problem is that you probably have a file name with a space in it. cat'ing a file in a for loop like that breaks if the line has more than one column - and a file name with spaces will be interpreted as more than one column.

Although I can not guarantee it, using a while loop might do it:

while read i 
    tar cvzf /dir/docs/oldXML$DATE.tgz "$i"
#rm -f "$i"
done <  /var/log/xmldel.log

The double quotes around "$i" is required if there is a hope of this working.

Report •

November 5, 2010 at 02:08:55
Thanks Nails! much apreciated

Report •
Related Solutions

Ask Question