find command error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command error
# 1  
Old 05-18-2012
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

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.
# 2  
Old 05-18-2012
Hi,

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

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

Quimer@

Last edited by Scott; 05-18-2012 at 10:17 AM.. Reason: Code tags
# 3  
Old 05-18-2012
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.
# 4  
Old 05-18-2012
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:
Code:
/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:
Code:
find /var/log -depth -name  "test*"  -exec rm -r {} \;

# 5  
Old 05-18-2012
Hi,

use option "-depth".

Quimer@
# 6  
Old 05-20-2012
Excellent..thank u so much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find command giving bad status error

In a fastload teradata utility I am trying to delete the files which are older than 30days using the find and rm command as following. find . -name 'xxx_*' -mtime +30 -exec rm -f {} \; I expect it to delete all the files older than 30 days but sometimes it gives an error : find: bad status--... (3 Replies)
Discussion started by: stelkar
3 Replies

2. Shell Programming and Scripting

find command -No such file error

Hi , I tried the below code to remove the files older that 30 days . #!/bin/ksh set -x file_path1="/home/etc" file_path2="/home/hst" file_nm="HST" days=30 find $file_path1/*$file_nm* -type f -mtime +$days -exec rm -f {} \; find $file_path2/*$file_nm* -type f -mtime +$days -exec rm... (3 Replies)
Discussion started by: smile689
3 Replies

3. Shell Programming and Scripting

Find command error having space in filename

Hi, I am working in solaris.I am using below script to copy the files from /usr/tmp to /usr/gm But while running this it is not considering the files list after the filename having space in them. Example:- compile_custom_pll.sh conv_data_sqlload.sh conv_sqlload.sh Copy of... (5 Replies)
Discussion started by: millan
5 Replies

4. Shell Programming and Scripting

find command error

Hi, We have a shell script which looks into a directroy for any folder older than 30 days and removes them. The command being used is find $ARCHIVE_DIR -type d -mtime +$PURGE_HIST_DAYS -exec rm -rf {} \; It removes some folders but then throw below errors for others: find:... (2 Replies)
Discussion started by: DejaVu
2 Replies

5. Shell Programming and Scripting

ksh - find command with 2 actions attached and error logging

Hi there, I'm encountering problems on an AIX system when using following in my script. find . -name *.edi -type f -exec sh -c 'scp {} $user@$server:$path || exit 5; mv {} $sent || exit 7' \; the error i get is following find: 0652-018 An expression term lacks a required... (4 Replies)
Discussion started by: Kerberos
4 Replies

6. UNIX for Advanced & Expert Users

find command error

Executing "find /abc -follow -ls" the message "find: cycle detected for /abc/def/ghi/ What does this mean? Thanks... (2 Replies)
Discussion started by: twk
2 Replies

7. Shell Programming and Scripting

Find Command in the script throw error

Hi I have script that is developed to serch for 30 days old Directory & Files and then remove them ... when i run it successfully removes the Directory & files & but it throw errors on the screen .. .. + find . -type f -mtime +30 -exec rm -f {} ; + exit please help me ?? I... (0 Replies)
Discussion started by: Beginner123
0 Replies

8. Shell Programming and Scripting

Perl Script Error with find command

Guys, I need to find all the files ending with either dmp or dmp.Z. This command is giving me error. @files =`find $path \(-name "*.dmp" -o -name "*.dmp.Z"\) -mtime +30`; sh: 0403-057 Syntax error at line 1 : `(' is not expected. Thanks in advance (4 Replies)
Discussion started by: MKNENI
4 Replies

9. UNIX for Dummies Questions & Answers

find command exec error

Hi All, i am writing a shell script in korn shell which deletes all the files in a directory once in every 10DAYS. the directory has different format files. the script has something like this; cd /home/data/pavi echo "Please Enter the Number of Days to search for" read DAYS... (2 Replies)
Discussion started by: pavan_test
2 Replies

10. Shell Programming and Scripting

I want to get the file which created the error when the find command was run

I want to get the file which created the error when the find command was run ? I am wrote a script to mail a list of files whose file size is ge than 0 and returns 0 but wen it finds a folder with only empty files it exits as 1. i need to modify it so that the return for this is also 0 (but it... (1 Reply)
Discussion started by: guhas
1 Replies
Login or Register to Ask a Question