- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- shell programming
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
10-08-2002 07:57 AM
10-08-2002 07:57 AM
Is there a better way to hadle this, other then capturing the output to a file?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:03 AM
10-08-2002 08:03 AM
Solutionon my system the 6th field on a line returned from bdf is the mount point... if your /mnt is not mounted, it will not be returned and MNT_CHECK should be null.
MNT_CHECK = `bdf|grep /mnt | awk '{print $6}'`
echo ${MNT_CHECK} # just to see if you get what you expect...
now set up some if statement that will verify your logic and execute other tasks...
Ted
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:03 AM
10-08-2002 08:03 AM
Re: shell programming
You can check if the exit code was succesful
bdf | grep /mnt
if [ $? != 1 ]
then
task
fi
HTH
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:03 AM
10-08-2002 08:03 AM
Re: shell programming
How about:
# bdf|grep -q /mnt && echo "It's mounted!"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:10 AM
10-08-2002 08:10 AM
Re: shell programming
if [ $A = 0 ]
then
command
exit
fi
Manoj Srivastava
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:17 AM
10-08-2002 08:17 AM
Re: shell programming
IMHO, James' approach is by far the coolest. :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:22 AM
10-08-2002 08:22 AM
Re: shell programming
The concept here is that no file is used. Rather the output of 'bdf' is piped to 'grep' which is run "quietly" (without output). The return code of grep is examined and only if it is non-zero then is your command (or commands as the example shows) executed:
# bdf|grep -q /mnt || ( echo "It's not mounted!";date )
You can exchange the double pipe (||) for a double ampersand (&&) and invert the logic.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:30 AM
10-08-2002 08:30 AM
Re: shell programming
Thank you for the explanations.
I wanted to assighn you 10 points, but somehow it turned to 0. Can I modify it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:31 AM
10-08-2002 08:31 AM
Re: shell programming
I would also recommend changing your grep arguments to only match for a filesystem called /mnt. All the above examples would also match something like /mntxxx or even /dev/vgxx/mnt...
Something like:
if bdf | grep -q " /mnt$"
then...
or:
if grep -q " /mnt " /etc/mnttab
then...
Would do the trick.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:37 AM
10-08-2002 08:37 AM
Re: shell programming
var=$(bdf|grep /mnt)
if [[ $var != "" ]]
then
# do your stuff here
fi
OR
if [[ $(bdf|grep /mnt|wc -l) -ne 0 ]]
then
# do your stuff here
fi
Take note that "bdf" command may hung if you got stale NFS filesystem or bad FS. I'm in favor of "mount -v" instead.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 08:45 AM
10-08-2002 08:45 AM
Re: shell programming
Well, once you assign points there's no changing them! ;-)
John Palmer makes a very good point. You could leverage his suggestion like this too:
# grep -q "/mnt " /etc/mnttab || ( echo "It's not mounted!";date )
Notice that I let 'grep' open the '/etc/mnttab' rather than spawn a separate process to do so, like 'cat /etc/mnttab|grep...'.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 09:05 AM
10-08-2002 09:05 AM
Re: shell programming
mount | grep -q '^/opt ' && echo "Yo, brother."
Should be more water-proof, I think. In general, I don't like reading /etc/mnttab directly.
Regards...
Dietmar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 10:07 AM
10-08-2002 10:07 AM
Re: shell programming
Das ist sehr gut!
Yes, I like that better. It's short, matches exactly what (and only what it should) and executes very quickly.
BTW, your new hat looks just like it was made for you! :-))
With warm regards...
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2002 11:24 AM
10-08-2002 11:24 AM
Re: shell programming
Vielen Dank fuer die Blumen! :)
Greetings to Sarasota.
Dietmar.