What happens when there aren't files that meet this criteria ? Can it delete any other directories ? I had a shocking output of the script yesterday as it looks to me that it has deleted quite a number of directories.
Could it be this command that generated this output ?
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/backup': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch/files': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch/files/lib': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch/files/lib/libn10.a': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch/files/lib32': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch/files/lib32/libn10.a': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch/etc': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch/etc/config': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/original_patch/etc/xml': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/rac': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/scratch': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/files': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/files/lib': Is a directory
rm: cannot remove `product/10.2.0/.patch_storage/6397938_Sep_21_2007_07_19_39/files/lib/libn10.a': Is a directory
It removed quite a lot of files from a number of directories. It has worked before. Could it be this script ? I've made sure that the script cd's to the right directory
Thank you Franklin.
The ARCH_DEST is obtained from within a Oracle database, but accidentally the database down when this happened. Could it be that it ran the command for all the directories ?
Also, if no .gz files are available, the the return code is non-zero. basically, i am trying to see if the deletion .gz is successful and if it fails, report it as an error.
Something like this
Delete_Archive() {
LogDest="select value from v\$parameter where name='standby_archive_dest';"
runSql "${LogDest}"
ARCH_DEST="${COUNT}"
cd ${ARCH_DEST}
echo `pwd` => pwd is sufficient
#find ${ARCH_DEST}/*.gz -mtime +0 -exec rm -f {} \;
rm *.gz => this deletes all .gz files!!
RC2=$? => now it gives the returncode of the rm command not the returncode of the find command
Replace the above code with:
pwd
find ${ARCH_DEST}/*.gz -mtime +0 -exec ls -l {} \; # Use ls -l first to be sure you get the expected files
# find ${ARCH_DEST}/*.gz -mtime +0 -exec rm -f {} \;
RC2=$?
put an if condition to check that ur sql returned the results successfully, otherwise the find command reads all the *.gz files from all the subdirectories and deletes.
Test with "ls" first.
Check that ARCH_DEST is not blank.
Use "-type f" to only find files.
Here's another version with some more points:
This version:
has no limit on the number of filenames.
does nothing if there are no files to delete (and does not error).
works if there are spaces in the filename or directory name.
"escapes" the "*" and the "." in the "-name" parameter to avoid false matches.
#!/bin/ksh
if [ -d "${ARCH_DEST}" ]
then
find "${ARCH_DEST}/" -name \*\.gz -type f -mtime +0 -print | while read FILENAME
do
ls -ald "${FILENAME}"
# rm "${FILENAME}"
done
else
echo "ARCH_DEST incorrect or missing: ${ARCH_DEST}"
fi
I am trying to move older files from adirectory to a archived folder. and I get the error "sh: /usr/bin/find: 0403-027 The parameter list is too long.". The following commnads is being used:
The error has disappeared but this command is picking up files from the subdirectories under dir5 as well. I want to archive only the files from currnet directory i.e. dir5.
I have made a slight change to the command. The target directory happens to be a subdirectory under the current directory.
How do I mdofiy this to pick up files from current directory only.
find /dir1/dir2/dir3/dir4/dir5 -type f -prune -mtime +2 | xargs -l50 -i mv -f {} /dir1/dir2/dir3/dir4/dir5/dir6
Works for me on AIX too (although the only system I have access to is AIX 6.1 (yours is 5.3). Are you sure you copied the command correctly and replaced both instances of dir5 with the real directory name, in the second case without the path?