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
MAKE-JPKG(1)						      General Commands Manual						      MAKE-JPKG(1)

NAME
make-jpkg - builds Debian packages from Java binary distributions SYNOPSIS
make-jpkg [OPTION]... [FILE] DESCRIPTION
make-jpkg builds a Debian package from the given Java distribution FILE. Supported java binary distributions currently include: * Oracle (http://www.oracle.com/technetwork/java/javase/downloads) : - The J2SE Development Kit (JDK), version 6 (update >= 10), 7 - The J2SE Runtime Environment (JRE), version 6 (update >= 10), 7 - The J2SE API Javadoc, version 6 (update >= 10), 7 (Choose tar.gz archives or self-extracting archives, do _not_ choose the RPM!) The following options are recognized: --full-name NAME full name used in the maintainer field of the package --email EMAIL email address used in the maintainer field of the package --changes create a .changes file --revision add debian revision --help display help text and exit --version output version information and exit Download a supported Java RE or SDK or API tar.gz or self-extracting archive from http://www.oracle.com/technetwork/java/javase/downloads and execute make-jpkg file with the downloaded file. The program asks the user for additional information and builds a Debian binary pack- age in the current directory. The program requires about 200 MB free disk space in a temporary directory. The temporary directory defaults to /tmp but you can specify an alternate directory by setting the environment variable TMPDIR. EXAMPLE
To install Oracle(TM) 7 Standard Edition JDK, download a release - 64 bits version of update 2 from http://www.oracle.com/technet- work/java/javase/downloads/jdk-7u2-download-1377129.html in this example - and invoke make-jpkg: make-jpkg <path_to_download_directory>/jdk-7u2-linux-x64.tar.gz This generate a Debian package in the current directory, that can be installed using dpkg: dpkg -i oracle-j2sdk1.7_1.7.0+update2_amd64.deb When you're done, you can delete initial download as well as generated package: rm <path_to_download_directory>/jdk-7u2-linux-x64.tar.gz oracle-j2sdk1.7_1.7.0+update2_amd64.deb ENVIRONMENT
TMPDIR base directory used for temporary files (defaults to /tmp) J2SE_PACKAGE_FULL_NAME full name used in the maintainer field of the package; if none is supplied then the default of "Debian Java Maintainers" is used. J2SE_PACKAGE_EMAIL email address used in the maintainer field of the package; if none is supplied the default of "pkg-java-maintain- ers@lists.alioth.debian.org" is used. SEE ALSO
update-java-alternatives(1) AUTHOR
This manual page was written by Hubert Schmid <j2se-package@z42.de>. It is now maintained by the Debian Java Maintainers <pkg-java-maintainers@lists.alioth.debian.org>. January 22, 2012 MAKE-JPKG(1)
All times are GMT -4. The time now is 12:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy