Hey guys I'm trying to put a script together that will find files older than 30 days and move them to a backup location. Once moved I would like the files deleted from the "prior" directory. I also have it set to email me the status of if the files moved or no. I'm definately not a programmer of any sorts but below was the command I'm using. I put this together from reading some forums on here.
cp -r -p `find /edi/aiprod/report -mtime +30` /edilogs/aiprodreport
ERRCODE=`echo $?`
if [ $ERRCODE != 0 ] ; then
echo "Failed" | mailx -s "EDI Report Maintenance"
xxxxxx@xxxxx.com
exit
else
echo "Successful" | mailx -s "EDI Report Maintenance"
xxxxxx@xxxxx.com
rm -r `find /edi/aiprod/report -mtime +30`
fi
The problem I'm having with this is that when the script runs it doesnt keep the same directory structure. It seems like any file in a sub directory does not get copied over. Also the files that get copied over are put into the main directory it won't creat the sub directory the file was copied from. Does anyone have any suggestions on a better approach?
For ex.
/edi/aiprod/CATERPILLAR/20081216.850.doc
would be copied to
/edilogs/aiprodreport/20081216.850.doc
Hopefully I made some sense of this. Any help would be much appreciated thanks a ton guys!