Re: check with a script open file(s) of a filmiest (735 Views)
Reply
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 1 of 14 (785 Views)
Accepted Solution

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,

 

 

Honored Contributor
Duncan Edmonstone
Posts: 5,684
Registered: ‎08-05-2000
Message 2 of 14 (774 Views)

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.

 


HTH

Duncan
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 3 of 14 (764 Views)

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
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 4 of 14 (756 Views)

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

 

Honored Contributor
Duncan Edmonstone
Posts: 5,684
Registered: ‎08-05-2000
Message 5 of 14 (751 Views)

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

 

 


HTH

Duncan
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 6 of 14 (743 Views)

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

sorry, you are right . my mistake.

Honored Contributor
Michael Steele_2
Posts: 4,934
Registered: ‎08-14-2002
Message 7 of 14 (735 Views)

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
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 8 of 14 (627 Views)

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

 

Honored Contributor
H.Merijn Brand (procura
Posts: 6,189
Registered: ‎10-13-1997
Message 9 of 14 (608 Views)

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
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 10 of 14 (604 Views)

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

Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 11 of 14 (602 Views)

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 ?



Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 12 of 14 (599 Views)

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

Honored Contributor
H.Merijn Brand (procura
Posts: 6,189
Registered: ‎10-13-1997
Message 13 of 14 (597 Views)

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
Valued Contributor
support_billa
Posts: 192
Registered: ‎06-27-2011
Message 14 of 14 (591 Views)

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

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.