home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 5.ddi / sbin / shutdown < prev    next >
Encoding:
Text File  |  1990-12-08  |  2.7 KB  |  146 lines

  1. #!/sbin/sh
  2. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  3. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  4. #      All Rights Reserved
  5.  
  6. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  7. #    UNIX System Laboratories, Inc.
  8. #    The copyright notice above does not evidence any
  9. #    actual or intended publication of such source code.
  10.  
  11. #ident    "@(#)/sbin/shutdown.sl 1.1 4.0 12/08/90 46632 AT&T-USL"
  12.  
  13. #    Sequence performed to change the init stat of a machine.
  14.  
  15. #    This procedure checks to see if you are permitted and allows an
  16. #    interactive shutdown.  The actual change of state, killing of
  17. #    processes and such are performed by the new init state, say 0,
  18. #    and its /sbin/rc0.
  19.  
  20. #    Usage:  shutdown [ -y ] [ -g<grace-period> ] [ -i<init-state> ]
  21.  
  22. if [ `pwd` != / ]
  23. then
  24.     echo "$0:  You must be in the / directory to run /sbin/shutdown."
  25.     exit 1
  26. fi
  27.  
  28. # Make sure /usr is mounted
  29. if [ ! -d /usr/bin ]
  30. then
  31.     echo "$0:  /usr is not mounted.  Mount /usr or use init to shutdown."
  32.     exit 1
  33. fi
  34.  
  35. #    Check the user id
  36. if [ -x /usr/bin/id ]
  37. then
  38.     eval `id  |  /usr/bin/sed 's/[^a-z0-9=].*//'`
  39.     if [ "${uid:=0}" -ne 0 ]
  40.     then
  41.             echo "$0:  Only root can run /sbin/shutdown."
  42.         exit 2
  43.     fi
  44. else
  45.     echo "$0:  can't check user id."
  46.     exit 2
  47. fi
  48.  
  49. grace=60
  50. askconfirmation=yes
  51.  
  52. if i386
  53. then
  54.     initstate=0
  55. else
  56.     initstate=s
  57. fi
  58.  
  59. while [ $# -gt 0 ]
  60. do
  61.     case $1 in
  62.     -g[0-9]* )
  63.         grace=`/usr/bin/expr "$1" : '-g\(.*\)'`
  64.         ;;
  65.     -i[Ss0156] )
  66.         initstate=`/usr/bin/expr "$1" : '-i\(.*\)'`
  67.         ;;
  68.     -i[234] )
  69.         initstate=`/usr/bin/expr "$1" : '-i\(.*\)'`
  70.         echo "$0:  Initstate $initstate is not for system shutdown."
  71.         exit 1
  72.         ;;
  73.     -y )
  74.         askconfirmation=
  75.         ;;
  76.     -* )
  77.         echo "$0:  Illegal flag argument '$1'"
  78.         exit 1
  79.         ;;
  80.     * )
  81.         echo "Usage:  $0 [ -y ] [ -g<grace> ] [ -i<initstate> ]"
  82.         exit 1
  83.     esac
  84.     shift
  85. done
  86.  
  87. if [ -x /usr/alarm/bin/event ]
  88. then
  89.     /usr/alarm/bin/event -c gen -e shutdown -- -t $grace
  90. fi
  91.  
  92. if [ -z "${TZ}"  -a  -r /etc/TIMEZONE ]
  93. then
  94.     . /etc/TIMEZONE
  95. fi
  96.  
  97. echo '\nShutdown started.    \c'
  98. /usr/bin/date
  99. echo
  100.  
  101. /sbin/sync
  102. cd /
  103.  
  104. trap "exit 1"  1 2 15
  105.  
  106. a="`/sbin/who  |  /usr/bin/wc -l`"
  107. if [ ${a} -gt 1  -a  ${grace} -gt 0 ]
  108. then
  109.     /usr/sbin/wall<<-!
  110.         The system will be shut down in ${grace} seconds.
  111.         Please log off now.
  112.  
  113.     !
  114.     /usr/bin/sleep ${grace}
  115. fi
  116.  
  117. /usr/sbin/wall <<-!
  118.     THE SYSTEM IS BEING SHUT DOWN NOW ! ! !
  119.     Log off now or risk your files being damaged.
  120.  
  121. !
  122. /usr/bin/sleep ${grace}
  123.  
  124. if [ ${askconfirmation} ]
  125. then
  126.     echo "Do you want to continue? (y or n):   \c"
  127.     read b
  128. else
  129.     b=y
  130. fi
  131. if [ "$b" != "y" ]
  132. then
  133.     /usr/sbin/wall <<-!
  134.         False Alarm:  The system will not be brought down.
  135.     !
  136.     echo 'Shut down aborted.'
  137.     exit 1
  138. fi
  139. case "${initstate}" in
  140. s | S )
  141.     . /sbin/rc0
  142. esac
  143.  
  144. echo "Changing to init state $initstate - please wait"
  145. /sbin/init ${initstate}
  146.