Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / unmount_nfs
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         mount_nfs
5 # RCS:          $Header:$
6 # Description:  A script to mount all nfs mounts. Note if the automounter is
7 #               running then this script will first shutdown the automounter.
8 #               This script returns 0 for success or non zero if it was unable
9 #               to umount all nfs mounts. This script must run as root.
10 # Author:       Andrew DeFaria, California Language Labs
11 # Created:      Fri Jun  6 10:31:51 PDT 1997
12 # Modified:     
13 # Language:     Korn Shell
14 #
15 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
16 #
17 ################################################################################
18 # Set me to command name
19 me=$(basename $0)
20
21 # Set adm_base
22 adm_base=${adm_base:-//sonscentral/Corporate/Software/adm}
23
24 # Set adm_fpath
25 adm_fpath=${adm_fpath:-$adm_base/functions}
26
27 # Source functions
28 . $adm_fpath/common
29
30 if is_not_root; then
31   error "This script must be run as root" 1
32 fi
33
34 integer automount_pid=$(process_is_running automount)
35 kill_automounter=yes
36
37 if [ $automount_pid -ne 0 ]; then
38   print "Attempting to shutdown the automounter..."
39   kill -15 $automount_pid
40
41   print "Waiting for the automounter to shutdown..."
42   integer max_tries=5
43   integer wait_time=10
44
45   while [ $max_tries -ne 0 ]; do
46     sleep 10
47     automount_pid=$(process_is_running automount)
48     process_is_running automount
49     if [ $automount_pid -ne 0 ]; then
50       print "The automounter ($automount_pid) is still running!"
51       print "I will wait $max_tries more time\c"
52       if [ $max_tries -gt 1 ]; then
53         print -u2 "s\c"
54       fi
55       print ". Waiting $wait_time seconds..."
56       sleep $wait_time
57     else
58       break
59     fi
60     let max_tries=max_tries-1
61   done
62 fi
63
64 automount_pid=$(process_is_running automount)
65 if [ $automount_pid -ne 0 ]; then
66   print "The automounter has not shutdown! Continuing..."
67 else
68   print "The automounter has been shut down successfully"
69   touch /etc/automounter_was_here
70 fi
71
72 print "\nAttempting to unmount all nfs mounts"
73 if [ "$OS" = "09" ]; then
74   /etc/umount -at nfs
75 else
76   /usr/sbin/umount -a -F nfs
77 fi
78
79 integer nfs_mounts_left=$(grep -c "nfs" /etc/mnttab)
80
81 if [ $nfs_mounts_left -eq 0 ]; then
82   print "All nfs filesystems have been successfully unmounted!"
83   exit 0
84 else
85   print "There \c"
86   if [ $nfs_mounts_left -eq 1 ]; then
87     print "is one filesystem left mounted:\n"
88   else
89     print "are $nfs_mounts_left filesystems left mounted:\n"
90   fi
91   grep nfs /etc/mnttab
92   exit 1
93 fi