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.
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: