View Single Post

   
  #2 (permalink)  
Old 01-05-2008, 09:09 AM
steven_nospam at Yahoo! Canada
 
Posts: n/a
Default Re: check if a filesystem is mounted

I think what you are doing is correct, but may be overly complicated.
You can check the status of the df command by checking the exit status
of the command "df /comx/data" and if it is non-zero it is not mounted.

Also, this script may be of use to you. It checks the type of file
system and whether it is mounted or not, then returns an exit status
based on that condition. You can then use that in a script when you are
trying to determine if a file system is mounted or if the file system
is large file enabled. (Just eliminate the verbose messages or pipe
them to /dev/null if you do not want them displayed.)

#!/bin/ksh
#
# Script: jfstype
#
# Usage: Checks the JFS to see if the selected mount point is a
standard
# JFS, JFS with large-file support, JFS2, or CDROM file
system.
# The script returns a message and an appropriate exit
status
# based on what it finds out.
#
# Syntax: jfstype [/filesystem_name]
# If no name is specified we check current directory.
#
################################################## #############################
integer ERRVAL=0
integer XSTS=0

if test "$1" = ""
then
MTPT=$(df . | grep "^/" |awk '{print $7}')
else
if test "$(echo $1|cut -c1)" = "-"
then
echo "\nProgram: jfstype"
echo "\nUsage: Returns a message and status code based on the
type of file
system"
echo "\nStatus Codes:"
echo " 0 = File system does not exist"
echo " 1 = Standard JFS"
echo " 2 = Compressed JFS"
echo " 3 = Standard JFS with Large File Enabled"
echo " 4 = Network file system"
echo " 5 = CDROM file system"
echo " 6 = Standard JFS2"
echo "51 = Standard JFS"
echo "52 = Compressed JFS"
echo "53 = Standard JFS with Large File Enabled"
echo "54 = Network file system"
echo "55 = CDROM file system"
echo "56 = Standard JFS2 "
exit 0
fi
MTPT=$1
fi

#################################################
# STATUS CODES WHEN FILE SYSTEM IS NOT MOUNTED: #
# #
# 0 = File system does not exist #
# 1 = Standard JFS #
# 2 = Compressed JFS #
# 3 = Standard JFS with Large File Enabled #
# 4 = Network file system #
# 5 = CDROM file system #
# 6 = Standard JFS2 #
#################################################
# STATUS CODES WHEN FILE SYSTEM IS MOUNTED: #
# #
# 0 = File system does not exist #
# 51 = Standard JFS #
# 52 = Compressed JFS #
# 53 = Standard JFS with Large File Enabled #
# 54 = Network file system #
# 55 = CDROM file system #
# 56 = Standard JFS2 #
#################################################

################################################## ##########
# If the lsfs returns a zero value, we found a file system #
################################################## ##########
lsfs ${MTPT} 1>/dev/null 2>/dev/null
ERRVAL=$?
if test ${ERRVAL} -ne 0
then
echo "Not found: ${MTPT}"
exit ${XSTS}
fi

FSTYPE=$(lsfs -c ${MTPT}|grep -v "^#"|cut -f3 -d':')
case ${FSTYPE} in
'jfs' ) {
if test "$(lsjfs ${MTPT} |grep -v "^#"|cut -f15 -d':')" =
"LZ"
then
echo "Found LZJFS:\c"
XSTS=2
elif test "$(lsjfs ${MTPT} |grep -v "^#"|cut -f16 -d':')" =
"true"
then
echo "Found LFEJFS:\c"
XSTS=3
else
echo "Found JFS:\c"
XSTS=1
fi
};;
'jfs2' ) {
echo "Found JFS2:\c"
XSTS=6
};;
'cdrfs') {
echo "Found CDRFS:\c"
XSTS=5
};;
'nfs') {
echo "Found NFS:\c"
XSTS=4
};;
esac

df ${MTPT} 1>/dev/null 2>&1
ERRVAL=$?
if test ${ERRVAL} -eq 0
then
echo "Mounted:${MTPT}"
XSTS=$(expr ${XSTS} + 50)
else
echo "Unmounted:${MTPT}"
fi

exit ${XSTS}

Reply With Quote