- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Test if there is a filesystem mounted
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
Forums
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
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
09-03-2007 10:51 PM
09-03-2007 10:51 PM
How can I test in a shell script if a filesystem is mounted on directory?
Thks,
Pedro
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2007 10:54 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2007 10:59 PM
09-03-2007 10:59 PM
Re: Test if there is a filesystem mounted
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2007 12:28 AM
09-04-2007 12:28 AM
Re: Test if there is a filesystem mounted
if grep $dir /etc/mnttab
then
etc.
Mark Syder (like the drink but spelt different)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2007 05:08 AM
09-04-2007 05:08 AM
Re: Test if there is a filesystem mounted
You should also use grep -q:
if grep -q $dir /etc/mnttab; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2007 10:10 AM
09-04-2007 10:10 AM
Re: Test if there is a filesystem mounted
Note that /etc/mnttab can get corrupt or
have missing record for a specific file system.
Do not rely on /etc/mnttab exclusively.
Here is a little snippet for /bin/sh and /bin/bash script:
#!/bin/sh
fsname="/opt"
if [ "`df $fsname | awk '! /awk/ && ! /Mounted on/ { if ( $NF == "'$fsname'" ) {print}}'`" ]
then
echo "PASS: $fsname mounted"
else
echo "FAIL: $fsname not mounted"
fi
Cheers,
VK2COT
PS. The thread is closed so do not worry about assigning points.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2007 06:15 PM
09-05-2007 06:15 PM
Re: Test if there is a filesystem mounted
I had a little trouble interpreting your script. First of all, you should have used bdf and not df, otherwise it won't work.
I don't understand why you want to exclude "awk"? ! /awk/
Also, you might want to use awk -v instead of something hard to understand with your stuttering quoting:
M=$(bdf $fsname | awk -v fsname=$fsname '! /Mounted on/ { if ($NF == fsname) print}')
if [ "$M" ]; then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2007 08:44 PM
09-05-2007 08:44 PM
Re: Test if there is a filesystem mounted
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2007 11:17 PM
09-05-2007 11:17 PM
Re: Test if there is a filesystem mounted
Dennis, thanks for the comments.
I used df(1) as I cut-and-pasted from
my home Linux server :)
Of course, bdf(1) is more suitable
for HP-UX.
As far as NFS slowdown is concerned,
one can avoid checking it by using:
bdf -t vxfs
bdf -t hfs
and similar
If NFS is really a problem, then the
server is unresponsive anyway, so the
file system is acting almost like
being unmounted...
Alas, if /etc/mnttab is corrupt,
and if one has bad luck,
waiting 30 seconds for syncer(1) to
update the file can be too long.
# uname -a
HP-UX myserv B.11.11 U 9000/800 1448733058 unlimited-user license
# cat /etc/mnttab
# df -k
# bdf
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol3 212992 137904 74560 65% /
/dev/vg00/lvol1 298928 56768 212264 21% /stand
/dev/vg00/lvol8 2621440 1416088 1198128 54% /var
/dev/vg00/lvol10 1048576 3388 981331 0% /var/tmp
/dev/vg00/lvol11 1048576 91944 896903 9% /var/opt/perf
/dev/vg00/lvignite 46612480 33730800 12781064 73% /var/opt/ignite
/dev/vg00/lvol12 1048576 160045 833055 16% /var/opt/OV
/dev/vg00/lvol9 4194304 1012790 2982812 25% /var/adm/crash
/dev/vg00/lvol7 2244608 1401872 836176 63% /usr
/dev/vg00/lvol4 524288 93240 427736 18% /tmp
/dev/vg00/lvol6 3276800 2529776 741224 77% /opt
/dev/vg00/lvol5 524288 5968 514592 1% /home
In other words, one might face a race
condition when tests fail because
/etc/mnttab is empty or corrupt.
Commands bdf(1), and mount(1) update
/etc/mnttab on HP-UX, but df(1) does not.
See real-life example above.
My point was not to trust single commands.
If something is critical double-check.
In my Perl OAT script, for example,
I check file systems in many ways. Once,
I found a very weird server that had
/stand unmounted. II was aksed to come to a specific customer and upgrade their server.
It was the first time ever I saw an HP-UX server running happily without /stand.
It is easy to replicate it (I just did it
on one server):
# umount /stand
# dmesg
Sep 6 21:13
Can't get kernel namelist
That is how I knew something was wrong :)
Cheers,
VK2COT