vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| dear aix gurus, is the following script realiable to check, if a filesystem is mounted or not ? thanx alot tim ps: mount point is /comx/data #!/bin/ksh # # test fs mount status # MOUNT_POINT=$(df -M /comx/data 2>/dev/null | awk ' (NR==2) {print $2} ') if [[ $MOUNT_POINT = "/" ]]; then echo "fs is not mounted: $MOUNT_POINT" else echo "fs is mounted: $MOUNT_POINT" fi |
| |||
| 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} |
| |||
| steven_nospam at Yahoo! Canada wrote: > 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. > that is not true. exit status of zero is just stating that it can check that directory to see if a filesystem exists there. if the directory exists, you'll get zero return regardless if it is mounted or not. |
| |||
| Darn! You are correct...It returns a non-zero value if the mount point does not exist. Okay, so I have to now tell our programmer we have a messed up script that may not be giving accurate info. Thx. Then I guess Tim's original method is the correct way. (At least the rest of our script seems right.) # df /qc Filesystem 1024-blocks Used Free %Used Mounted on /dev/qclv 806912 699460 107452 87% /qc / # echo $? 0 / # unmount /qc / # df /qc Filesystem 1024-blocks Used Free %Used Mounted on /dev/hd4 57344 49496 7848 87% / / # echo $? 0 |
| |||
| Actually Tim, Looking it over, your file system checking for "/" may actually match the root mount point when your file system is not mounted. based on the test I just did, you should probably try to compare the file system name to the same name...in other words if test "$MOUNT_POINT" = "/comx/data" then echo "File System is mounted" else echo "not mounted" fi (This is why I should never try to answer usenet before my morning coffee...) |
| |||
| Tim Moor wrote: > dear aix gurus, is the following script realiable to check, if a filesystem is mounted or not ? A more lightweight method often used is: When creating the mountpoint directory.. #mkdir /mnt/mymount Add a marker file in the underlying FS: #touch /mnt/mymount/warning_mount_missing Then use a simple presence test for the marker to detect a missing mount. Note that you probably want to add appropriate chown/chmod, and check owner as well, to avoid problems with malicious users that have write access. Eric |
| |||
| Hi Tim, this should to the trick. .... as you get in MOUNT_POINT the mount point value (if mounted) or you get the upper-level filesystem (no matters what it is). Also, you cannot use your variable MONT_POINT if the computed value is not the one expected... Retagds, Stephane #!/bin/ksh # # test fs mount status # MOUNT_POINT=$(df /comx/data 2>/dev/null | awk ' (NR==2) {print $NF}') if [[ $MOUNT_POINT != /comx/data ]] then echo "fs is not mounted: /comx/data" else echo "fs is mounted: $MOUNT_POINT" fi |
| |||
| thanks to all of you for your help tim "Tim Moor" <tim.moor@nospam.com> schrieb im Newsbeitrag news:4428f9f4$1_2@news.bluewin.ch... > dear aix gurus, > is the following script realiable to check, if a filesystem is mounted or > not ? > > thanx alot > tim > > ps: mount point is /comx/data > > #!/bin/ksh > # > # test fs mount status > # > MOUNT_POINT=$(df -M /comx/data 2>/dev/null | awk ' (NR==2) {print $2} ') > > if [[ $MOUNT_POINT = "/" ]]; then > echo "fs is not mounted: $MOUNT_POINT" > else > echo "fs is mounted: $MOUNT_POINT" > fi > > |
| |||
| Tim Moor wrote: > dear aix gurus, > is the following script realiable to check, if a filesystem is mounted or > not ? > > thanx alot > tim > > ps: mount point is /comx/data if ( mount | grep -q "[[:space:]]/comx/data[[:space:]]" ) ; then echo TRUE else echo FALSE fi hth Hajo |
| ||||
| Tim Moor wrote: > MOUNT_POINT=$(df -M /comx/data 2>/dev/null | awk ' (NR==2) {print $2} ') I would use the mount command and not the df command because if your filesystem is on nfs and the server is not responding your script will hang until the server is back. See hayo's post for a suggestion. Markus |