find command error

Hi folks,

I am trying a small script to delete a files from multiple servers having a common pattern.

I use this code

for i in `seq -w 25 100`
do
        echo "************host server-name*********"


        ssh -p 22022 server-name 'echo `hostname` && find /var/log  -name  "test*"  -exec rm -r {} \;' >>/tmp/test.log

        if [ $? -gt 0 ]

        then echo "some error , fix it "

        else echo "files deletion successful"

        fi

        done;

however when a directory is deleted, I see errors like "no such file or directory" and "some error, fix it" ...while in actual , the dir and files inside are deleted from that server. I dont want to see those errors ? please help.

Hi,

add "2> /dev/null" in your line command to redirect errors messages.

 ssh -p 22022 server-name ... 2> /dev/null

Quimer@

question, is, when find command is successfully deleting files , then why its throwing error, and the problem beneath is , its exit status also becomes non zero and my print message gets changed.

I believe it is because find is trying to descend into directory that no longer exists -- it was deleted with the exec call. Look at the output of find, it starts with the root dir, and descends deeper:

/path/to/dir
/path/to/dir/file1
/path/to/dir/file2
/path/to/dir/subdir
...

It forks a rm -r command but has no way of nowing that the rootdir has been deleted with this fork.

So what you need, is the -depth option, which processes the directory contents first:

find /var/log -depth -name  "test*"  -exec rm -r {} \;

Hi,

use option "-depth".

Quimer@

Excellent..thank u so much