Sponsored Content
Top Forums Shell Programming and Scripting Can you use find with ps or doing find excluding file in use Post 302981232 by newbie_01 on Thursday 8th of September 2016 04:18:04 PM
Old 09-08-2016
Can you use find with ps or doing find excluding file in use

Hi,

I am currently using the find below to remove old files. I am redirecting the listing to a file and then use a while-loop and do a rm

Code:
cd ${directory}
find . \( ! -name . -prune \) \( -type f -name "*.trc" -mtime +10 \) | sed 's#^./##' | sed "s#^#${directory}/#" 2>/dev/null | tee -a /tmp/rm_list_trc.txt
find . \( ! -name . -prune \) \( -type f -name "*.trm" -mtime +10 \) | sed 's#^./##' | sed "s#^#${directory}/#" 2>/dev/null | tee -a /tmp/rm_list_trm.txt

I've now just found out that some of the files that I am removing are actually still in use. Is it possible to tell find to do a fuser / lsof check and not do the remove if the file is in user?

Examples of these files that I want to exclude for getting removed are as below:


Code:
$ date
Fri Sep  9 07:50:44 NZST 2016
$ pwd
/u01/app/oracle/admin/qual1/bdump
$ ps -ef | grep qual1 | grep lgw
oracle   29112     1  0 Sep08 ?        00:00:01 ora_lgwr_qual13
$ ls -altr *lgw*trc
-rw-rw---- 1 oracle oinstall 955 Sep  8 11:35 qual13_lgwr_15798.trc
-rw-rw---- 1 oracle oinstall 805 Sep  8 11:40 qual13_lgwr_29112.trc
$ ls -altr *lgw*trm
ls: *lgw*trm: No such file or directory
$ date
Fri Sep  9 07:51:14 NZST 2016
$ ps -ef | grep qual1 | grep ora_p
oracle   21816     1  0 07:47 ?        00:00:00 ora_pz99_qual13
oracle   21818     1  0 07:47 ?        00:00:00 ora_pz98_qual13
oracle   29039     1  0 Sep08 ?        00:00:01 ora_pmon_qual13
oracle   29047     1  0 Sep08 ?        00:00:00 ora_psp0_qual13
$ ls -altr qual1*p*trc
-rw-rw---- 1 oracle oinstall 1770402 Sep  8 11:24 qual13_pmon_26250.trc
-rw-rw---- 1 oracle oinstall     890 Sep  8 22:00 qual13_pz98_31759.trc
-rw-rw---- 1 oracle oinstall     892 Sep  8 22:00 qual13_pz97_31903.trc

$ ls -altr *lgwr*
-rw-rw---- 1 oracle oinstall 955 Sep  8 11:35 qual13_lgwr_15798.trc
-rw-rw---- 1 oracle oinstall 805 Sep  8 11:40 qual13_lgwr_29112.trc
$ ps -ef | grep lgwr | grep prrq
oracle   29112     1  0 Sep08 ?        00:00:01 ora_lgwr_qual13
$ fuser qual13_lgwr_29112.trc
qual13_lgwr_29112.trc: 29112
$ pwd
/u01/app/oracle/admin/qual1/bdump
$ lsof /u01/app/oracle/admin/qual1/bdump/qual13_lgwr_29112.trc
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
oracle  29112 oracle    2w   REG  253,3      805 8357085 /u01/app/oracle/admin/qual1/bdump/qual13_lgwr_29112.trc
$

While these files may not have been modified for awhile and meet the find criteria for removal based on -mtime, we need to keep them as sometimes Oracle requests for these files if we log a call with them.

Currently, in the while-loop that I am using to do the rm, I am now doing a lsof or fuser now as well before doing the rm? Perhaps someone know of any better way of doing this.

Thanks in advance.
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

find excluding the hidden files

Hi , I am trying to use the find command with delete in a directory . Even though i use a wil character search the find command is checking the hidden files which inturn results in error . Can i avoid look that into the hidden files ?? I am using HP unix . find /cv1/ -name "ite*"... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

2. UNIX for Advanced & Expert Users

find excluding a directory and a file

Hi I have some 5 folders and two files in the current directory. I want to delete all, expect one folder(files in the folder too should not be deleted) and a file in the current directory. Lets say the folder and file that should not be deleted as 'a'(folder name) and 'b'(file name). Can you... (1 Reply)
Discussion started by: ammu
1 Replies

3. UNIX for Dummies Questions & Answers

Excluding directories with find

How do I exclude directories with the find command on Solaris? I want to skip the directories /proc and /shared. find / -nouser -print This shows me all files and directories that don't have an owner but I need to skip /shared and /proc. I've been able to get it to work on Linux... (3 Replies)
Discussion started by: x96riley3
3 Replies

4. Solaris

how to find out the file's name excluding string?

Hello, Under one directory, I can use below command to find out the file names with string "Export terminated successfully without warnings" grep -i -l "Export terminated successfully without warnings" *.* My question is : how I find out the file names without including string "Export... (5 Replies)
Discussion started by: GreatJerry
5 Replies

5. UNIX for Dummies Questions & Answers

Need help in excluding a particular directory using Find commad

Hi, I have a directory structure as below /home/gad/Merl/a/a1.txt /home/gad/Merl/b/a1.txt /home/gad/Merl/c/a1.txt How can I find the file a1.txt but not from directory 'a' and it(the filw) should loaded 6 days ago.. Can any one pls help,quick reply much appriciated.. Thanks. (1 Reply)
Discussion started by: jagadish_gaddam
1 Replies

6. Shell Programming and Scripting

Find all files for a user, excluding a directory

I have been searching, and cannot find an answer for this. I am trying to find all files for a user, lets call him (test001), and I want to exclude a specific directory. Here is the command I run, it finds all files: find / -user test001 I get this result: > find / -user test001 ... (4 Replies)
Discussion started by: steve2x4
4 Replies

7. Shell Programming and Scripting

Excluding directories from a find

I've looked at a few similar threads, but I can't bridge from those examples to what I'm working on, so I'm hoping someone can help. I want to extend the following statement find $PathToCheck -type f \( -not -iwholename "$ScriptDir/*" \) -exec md5sum "{}" \;>$NewSigs to exclude several... (9 Replies)
Discussion started by: nixie
9 Replies

8. Shell Programming and Scripting

Find command excluding directories and some files

hello. I try to print a list of files but excluding some directories and some files. I would like to write a command for : find "from_dir" "ignore dir1, dir2, ..." "ignore file1, file2,...." "where file are older than 2017-02-03T06:00:00" Note that "DO_IT" is a local function in the script... (5 Replies)
Discussion started by: jcdole
5 Replies

9. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

10. UNIX for Beginners Questions & Answers

Find file with extension and excluding directory

Hi, I have an inquiry on how do I use the find command in Solaris Unix to find some file ends with extension : txt, err in the root directory with modified date of 30days and this find command will also need to exclude b directory and its subdirectory. All the files from the above find criteria... (5 Replies)
Discussion started by: snowfrost88
5 Replies
hal-find(1M)						  System Administration Commands					      hal-find(1M)

NAME
hal-find, hal-find-by-capability, hal-find-by-property - search HAL global device list SYNOPSIS
hal-find-by-capability --capability capability [--help] [--verbose] [--version] hal-find-by-property --key key --string value [--help] [--verbose] [--version] DESCRIPTION
The hal-find commands, hal-find-by-capability and hal-find-by-property, search the Hardware Abstraction Layer (HAL) device list by speci- fied criteria and displays results on the standard output. hal-find-by-capability searches by capability, such as volume or block. hal- find-by-property searches by property, such as block.is_volume or volume.disc.has_audio. OPTIONS
The following options are supported: --capability capability HAL device capability to search for. --help Display list of options. --key key The key to the property that is the basis of the search. --string value The string value associated with the property that is the basis of the search. --verbose Verbose mode. --version Display version and exit. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWhalr | +-----------------------------+-----------------------------+ |Interface Stability |Volatile | +-----------------------------+-----------------------------+ SEE ALSO
hald(1M), attributes(5), hal(5) SunOS 5.11 22 Aug 2006 hal-find(1M)
All times are GMT -4. The time now is 01:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy