- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- check with a script open file(s) of a filesystem
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
- 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
- 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