Operating System - HP-UX
1777283 Members
2862 Online
109066 Solutions
New Discussion

Re: 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

support_billa
Valued Contributor

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

hello,

 

interesting behaviour between HPUX 11.23 and HPUX 11.31 :

 

fuser show different result, when it is used in a pipe:

 

test:

 

mkdir /tmp/fuser_dir

HPUX 11.31:

fuser -f /tmp/fuser_dir  2>/dev/null | wc -l
result: 0

 

info about /usr/sbin/fuser :
what /usr/sbin/fuser                  
/usr/sbin/fuser:
fuser.c $Date: 2010/01/12 19:01:40 $Revision: r11.31/1 PATCH_11.31 (PHCO_40769)
$Revision: @(#) fuser R11.31_BL2010_0112_2 PATCH_11.31 PHCO_40769

HPUX 11.23:

 

fuser -f /tmp/fuser_dir  2>/dev/null | wc -l
result: 1   # <------  wrong 

what /usr/sbin/fuser                  
/usr/sbin/fuser:
     $Revision: B11.23.0409LR

workaround for 11.23:


fuser -f /tmp/fuser_dir  2>/dev/null | grep -v "^$" | wc -l
   
ok ?

James R. Ferguson
Acclaimed Contributor

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


@support_billa wrote:

test : filesystem is read only

fuser : 0.1 sec

lsof    : 74 sec


It would be nice to know what options you used when you ran 'lsof'.

 

Regards!

 

...JRF...

H.Merijn Brand (procura
Honored Contributor

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

# time lsof /tmp
:
0.03u 4.76s 0:05.22 91.7%
# time fuser -c /tmp
:
0.00u 0.02s 0:00.02 100.0%
# time lsof /tmp/*
:
0.02u 4.59s 0:04.72 97.6%
# time fuser /tmp/*
:
0.02u 0.67s 0:00.70 98.5%
# time lsof /usr/lib/*
:
0.05u 4.74s 0:05.54 86.4%
# time fuser /usr/lib/*
:
0.01u 0.22s 0:00.25 92.0%
#

 I think I've just proven myself wrong on the speed :)

The output of lsof however is still way more usable. 

Enjoy, Have FUN! H.Merijn
support_billa
Valued Contributor

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

hello,

 

@ It would be nice to know what options you used when you ran 'lsof'.

 

i tested "lsof" without options : 1:32 min

"lsof" with "-s +D" : 1:20 min

 

regards