- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: check with a script open file(s) of a filesyst...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2011 06:53 AM
06-27-2011 06:53 AM
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,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2011 09:55 AM
06-27-2011 09:55 AM
SolutionHi,
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](/html/assets/hpe_banner_SME_signature.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2011 10:25 AM
06-27-2011 10:25 AM
Re: check with a script open file(s) of a filmiest
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2011 10:07 PM
06-27-2011 10:07 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2011 01:47 AM
06-28-2011 01:47 AM
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](/html/assets/hpe_banner_SME_signature.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2011 02:44 AM
06-28-2011 02:44 AM
Re: check with a script open file(s) of a filmiest
sorry, you are right . my mistake.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2011 10:49 AM
06-28-2011 10:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2011 04:17 AM
09-23-2011 04:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2011 05:55 AM
09-23-2011 05:55 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2011 06:24 AM
09-23-2011 06:24 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2011 06:29 AM
09-23-2011 06:29 AM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2011 06:33 AM
09-23-2011 06:33 AM
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2011 06:43 AM
09-23-2011 06:43 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2011 07:27 AM
09-23-2011 07:27 AM
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