Strange behavior of find and rm command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange behavior of find and rm command
# 1  
Old 05-12-2015
Hammer & Screwdriver Strange behavior of find and rm command

Hi

I run the below command to find and delete *.xml files 90 or more days old.

Code:
find . -type f -name '*.xml' -mtime +90 -exec rm {} \;
find: stat() error ./Hello/2014_EMPTY.xml: No such file or directory
./Hello/2014_EMPTY_8011.xml: No such file or directory
.....
....

If the file does not exists why is the my find even finding it and trying to delete something that does not exist?

Is it caching the find results causing this problem ?

I was not seeing this behaviour. Any guesses on how can i get my command working ?

I am on Unix Sparc.

Last edited by mohtashims; 05-12-2015 at 04:03 PM..
# 2  
Old 05-12-2015
First off, add echo before rm. Never ever ever run a batch deletion script you haven't tested.
# 3  
Old 05-12-2015
Quote:
Originally Posted by Corona688
First off, add echo before rm. Never ever ever run a batch deletion script you haven't tested.
This is suppose to run as a crontab.

I had use this command with rm -i option and it all looked good in the first run.

Could be my crontab tab is running in the background and its is deleting the files and when i run it manually it does not find the file .. .thats my wild guess. But how can i confirm ?

ps -ef | grep purge.sh
does not yield any results where purge.sh has that find and remove command i post in the OP; to show that the BG process is running or maybe there is a problem with the ps command Smilie

Not sure what has happened now ?
# 4  
Old 05-12-2015
An error message like that usually means that another process removed that file while find was walking the file hierarchy. In other words:
  1. find used readdir() or getdents() to read a name from the directory it is processing,
  2. another process unlinks or renames the filename just read by find, and then,
  3. find tries to stat() the file to check the file's timestamps and gets the error you listed.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 5  
Old 05-12-2015
Say if another process as part of the crontab is running in the background that is deleting the file ... how can i find it's pid ?

The disk space usuage is reducing indicating that there must be a process running in the bg as part of the crontab.

Both the below commands do not yield any results.

Code:
bash-3.2$ /usr/ucb/ps -auxwww | grep purge*
bash-3.2$ /usr/ucb/ps -auxwww | grep find*

How can i stop the process ?
# 6  
Old 05-12-2015
Nothing says that the other process that removed, moved, or deleted that file was being run by another find command nor that it had been started by cron. Anybody logged on to your network with write access to the directory in question could remove a file. And, by the time you see the error message, that process could already be gone. There might not be a running process left to find. If you have process accounting running, you might be able to find who was running another process at the time find reported the error.

Of course if you were running the two copies of the same script at the same time, you could easily see several errors like that as they fight with each other trying to be the first one to find and process the selected files. But, if you have only seen this once, it is more likely that someone manually removed a file while your cron job was running.
# 7  
Old 05-13-2015
I hate find I've found it be to FAIL so many more times than successful.

You'd see better speed (and shorter arguments) ls -1'ing to a temp file, grep'ing the tmp, then cleaning up.

Find is THAT slow and shi**y.

Last edited by rbatte1; 05-13-2015 at 09:13 AM..
This User Gave Thanks to ampsys For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Strange behavior from kill command

I am getting some strange behaviour from the kill command. When I run the which command it says it points to /usr/bin/kill. When I look at my PATH I have /usr/bin in it. So why does running kill or /usr/bin/kill produce different outputs? ghost ~ $ which kill /usr/bin/kill ghost ~ $ kill... (5 Replies)
Discussion started by: cokedude
5 Replies

2. Shell Programming and Scripting

Strange Ctrl+C behavior

Hello All, I have a strange issue. I've created a shell script which connects to RMAN (Oracle Recovery Manager) and executes full DB backup. I then executed this script with nohup and in the background: $ nohup my_script.sh > logfile.log 2>&1 &The issue is that when I tried to take a look into... (6 Replies)
Discussion started by: JackK
6 Replies

3. Shell Programming and Scripting

Strange behavior of grep

Hi All, I am facing a strange problem while grepping for a process. Here is the small script that i have written. It will look for any process running with the parameter passed to the script. If no process is running it should print appropriate message. $ cat t.ksh #!/bin/ksh set -x ... (9 Replies)
Discussion started by: veeresh_15
9 Replies

4. AIX

Strange behavior with tar

I am trying to create an archive using tar. I am specifying a list of directories using the -L option. For testing purposes I created a simple directory structure: /backup/test /backup/test/test1 /backup/test/test2 The file specified by the -L option, named files.txt, contains:... (8 Replies)
Discussion started by: judykstra
8 Replies

5. UNIX for Advanced & Expert Users

Behavior of Find command

Centos 5.8 Lets say I have 2 nfs shares mounted to /folder1 and /folder2. If I do a find / -name *something* Will it also search the 2 nfs shares ? If so is there a way to avoid this? Thanks (2 Replies)
Discussion started by: whegra
2 Replies

6. AIX

Strange memory behavior

Hello together, i have a strange memory behavior on a AIX 7.1 System, which i cannot explain. The Filesystem-Cache will not be grow up and drops often after few minutes. I know if a file was deleted, that the same segment in the FS-Cache will also be cleared. But i am not sure if this is the... (8 Replies)
Discussion started by: -=XrAy=-
8 Replies

7. Ubuntu

Ubuntu strange behavior

It is so till login screen. I mean that when I boot my computer, Ubuntu shows a splash screen with mouse instead of Ubuntu logo and in the login screen it shows XUbuntu login screen... It began when I upgraded to previous kernel, I suppose, but I'm not sure... I can't say that it annoys me very... (6 Replies)
Discussion started by: Sapfeer
6 Replies

8. Programming

Strange behavior in C++

I have the following program: int main(int argc, char** argv){ unsigned long int mean=0; for(int i=1;i<10;i++){ mean+=poisson(12); cout<<mean<<endl; } cout<<"Sum of poisson: "<< mean; return 0; } when I run it, I get the... (4 Replies)
Discussion started by: santiagorf
4 Replies

9. Shell Programming and Scripting

strange behavior of find with xargs

Help me understand the right output. We have two machines. The first one is HP-UX machine1 B.11.00 U 9000/800 694339343 unlimited-user license The second one is AIX machine2 2 5 00067B2F4C00 with AIX version 5.2.0.0 Here is the command that I use on both systems on different... (9 Replies)
Discussion started by: jerardfjay
9 Replies
Login or Register to Ask a Question