find command -No such file error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find command -No such file error
# 1  
Old 11-13-2013
find command -No such file error

Hi ,

I tried the below code to remove the files older that 30 days .

Code:
#!/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 -f {} \;

The file with the abvoe required name doesn't exist in the past 30 days .
But still I want the script to run by ignoring the following error .
The following error stops executing the another find command in my script .
Error is:
Code:
find: stat() error /home/etc/*HST*: No such file or directory

Please Suggest
# 2  
Old 11-13-2013
Quick and dirty, suppress ALL error messages:
Code:
set +e # on error continue
find $file_path1/*$file_nm* -type f -mtime +$days -exec rm -f {} \; 2>/dev/null
find $file_path2/*$file_nm* -type f -mtime +$days -exec rm -f {} \; 2>/dev/null

Or use a for loop and test if each file exists
Code:
for file in $file_path1/*$file_nm*  $file_path2/*$file_nm*
do
  [ -e "$file" ] &&
  find "$file" -type f -mtime +$days -exec rm -f {} \;
done


Last edited by MadeInGermany; 11-13-2013 at 05:58 AM..
This User Gave Thanks to MadeInGermany For This Post:
# 3  
Old 11-13-2013
Change the command to:
Code:
find $file_path1 -name "*$file_nm*" -type f -mtime +$days -exec rm -f {} \;

as it should be.
This User Gave Thanks to Scott For This Post:
# 4  
Old 11-13-2013
Specify the name as a parameter:
Code:
find $file_path1 -name *$file_nm* -type f -mtime +$days

This User Gave Thanks to CarloM For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

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*" ... (5 Replies)
Discussion started by: gauravsharma29
5 Replies

3. Shell Programming and Scripting

wanted to find both link file and ordinary file using single find command

find . -type fl o/p is only the ordinary file. where in it wont give the link files. (2 Replies)
Discussion started by: nikhil jain
2 Replies

4. Shell Programming and Scripting

Find multiple string in one file using find command

Hi, I want find multiple string in one file using find coomand. And keeping it in one variable.grep is not working. (5 Replies)
Discussion started by: vivek1489
5 Replies

5. Shell Programming and Scripting

How to use grep & find command to find references to a particular file

Hi all , I'm new to unix I have a checked project , there exists a file called xxx.config . now my task is to find all the files in the checked out project which references to this xxx.config file. how do i use grep or find command . (2 Replies)
Discussion started by: Gangam
2 Replies

6. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

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

8. UNIX for Dummies Questions & Answers

how to find a file named vijay in a directory using find command

I need to find whether there is a file named vijay is there or not in folder named "opt" .I tried "ls *|grep vijay" but it showed permission problem. so i need to use find command (6 Replies)
Discussion started by: amirthraj_12
6 Replies

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

10. Shell Programming and Scripting

how to find a file in UNIX without find command?

given a start directory,a filename,how to find it? (3 Replies)
Discussion started by: bluo
3 Replies
Login or Register to Ask a Question