Operating System - HP-UX
1745858 Members
4547 Online
108723 Solutions
New Discussion

check with a script open file(s) of a filesystem

 
SOLVED
Go to solution
support_billa
Valued Contributor

check with a script open file(s) of a filesystem

hello,

 

what 's the best way to check with a script open file(s) of a filesystem,

may to handle in a script a question like " if  " open files then ....

 

commands :

fuser , lsof ?

 

to parse with fuser it is no easy because :

 

fuser -c /filesystem ; echo $?            <= no "error-code"

 

other idea to detect ,, if open files exist :

 

fuser -c /filesystem
/filesystem:     4033mcto

fuser -c /filesystem 2>&1 | sed "s|/filesystem: *||g" | wc -c

 

regards,

 

 

13 REPLIES 13
Solution

Re: check with a script open file(s) of a filmiest

Hi,

 

One nice feature of fuser is that only the PIDs of active processors go to stdout - everything else goes to stderr,

so something like:

 

# fuser -c /myfilesystem 2>/dev/null | wc -l

 will print 0 if there are no processes accessing the filesystem and >0 if there are processes accessing the filesystem.

 


I am an HPE Employee
Accept or Kudo
support_billa
Valued Contributor

Re: check with a script open file(s) of a filmiest

Hello, thx, i didn't see this feature in the man page. Great,so i put your command to my script. regards
support_billa
Valued Contributor

Re: check with a script open file(s) of a filmiest

hello,

 

fuser -c /myfilesystem 2>/dev/null | wc -l

 

did you test it ?

 

why : fuser  don't display process(es) in every line !

 

better ??? : fuser -c /myfilesystem 2>/dev/null | wc -w

 

it test it with fs /var (it is in use with many processes)

fuser -c /var 2>/dev/null | wc -l    => it is 1

 

regards

 

Re: check with a script open file(s) of a filmiest

Yes I tested it. If you look what I said, I indicated the code would print >0 if there were processes active. I didn't say it would print out the number of active processes on the filesystem. If that's what you wanted you should have said that in your inital post, and I would have suggested wc -w

 

 


I am an HPE Employee
Accept or Kudo
support_billa
Valued Contributor

Re: check with a script open file(s) of a filmiest

sorry, you are right . my mistake.

Michael Steele_2
Honored Contributor

Re: check with a script open file(s) of a filmiest

HI

 

And I've traveled this road before.  My solution was to create a script that relied upon the awk field separator arguement instead of the awk line separator arguement.

 

	   -F fs	  Specify regular expression used to separate
			  fields.  The default is to recognize space and tab
			  characters, and to discard leading spaces and
			  tabs.	 If the -F option is used, leading input
			  field separators are no longer discarded.

 

ra:/home/vbe $ fuser -cu /opt
/opt: 3738mto(root) 3116mt(root) 3729mto(root) 3225mto(lp) 29018mcto(ratel) 3259mto(root) 3263mto(root) 3733mto(root) 3588mt(root) 3301mto(root) 3354mt(root) 3687co(nursery) 527mcto(omv) 3392mto(root) 3724mto(root) 3712mto(root) 3741mto(root) 4289mcto(omv) 3755mto(root) 4281mcto(omv) 27936c(ratel) 5320mto(root) 16447c(ratel) 7269mto(root) 4808mct(root) 5332mto(root) 5333mto(root) 1435mt(root) 29005c(ratel) 28971c(vbe) 14287c(vbe) 26547c(ratel) 28972c(vbe) 21845c(ratel) 14305mt(vbe) 1947co(nursery)

 

Roughly,

 

fuser -ck /opt | awk -F ")" >> work file

cat work file | sed 's/\)' -e 's/\('

 

You end up with a work file that looks something like:

 

16447c ratel

7269mto root

26547c ratel

...etc.

 

 

 

Support Fatherhood - Stop Family Law
support_billa
Valued Contributor

Re: check with a script open file(s) of a filmiest

hello,

 

@ fuser -ck /opt | awk -F ")" >> work file

@ cat work file | sed 's/\)' -e 's/\('

 

be careful with "fuser" ... -k

 

i create following command to get information about open files :

 

for f in $( fuser -c /opt 2>/dev/null |tr -s "[:blank:]" "\n" |grep -v "^$" )
do
  ps -ef |grep -w $f |grep -v grep
done

or "lsof" , which runs at our systems longer

 

H.Merijn Brand (procura
Honored Contributor

Re: check with a script open file(s) of a filesystem

In general, I find lsof both faster and more reliable than fuser on all my HP-UX boxes.

Enjoy, Have FUN! H.Merijn
support_billa
Valued Contributor

Re: check with a script open file(s) of a filesystem

hello H.Merijn,

 

@ In general, I find lsof both faster and more reliable than fuser on all my HP-UX boxes.

lucky guy , exactly the opposite is true on all of  my HP-UX boxes.

 

test : filesystem is read only

fuser : 0.1 sec

lsof    : 74 sec

 

for traceing "lsof" is better, i agree to you

 

regards