home *** CD-ROM | disk | FTP | other *** search
/ ftp.jcu.edu.au / 2014.06.ftp.jcu.edu.au.tar / ftp.jcu.edu.au / v6.3.2b / SWBD63 / fabos-6.3.2b-10.ppc.rpm / fabos-6.3.2b.10.cpio.gz / fabos-6.3.2b.10.cpio / fabos / libexec / inetdUpdate < prev    next >
Text File  |  2010-11-10  |  3KB  |  98 lines

  1. #!/bin/sh
  2. #
  3. #    Copyright (c) 1996-2002 Brocade Communications Systems, Inc.
  4. #    All rights reserved.
  5. #
  6. #    Initialization script to start/stop network services based on
  7. #    chassis configuration.
  8.  
  9. # Commands
  10. GREP=/bin/grep
  11. SED=/bin/sed
  12. CAT=/bin/cat
  13. CUT=/usr/bin/cut
  14. PS=/bin/ps
  15. NETSTAT=/bin/netstat
  16. KILL=/bin/kill
  17. KILLALL=/usr/bin/killall
  18. INETD_PROC=/usr/sbin/inetd
  19.  
  20. RESTART_INETD="0"
  21.  
  22. # No arguments, then show Telnet status
  23. #if [ $# == 0 ]; then
  24.     CHASSIS_FILE="/etc/fabos/fabos.chassis.conf"
  25. #else
  26. #    CHASSIS_FILE=$1
  27. #fi
  28.  
  29. # Only accept 1 argument
  30. #if [ $# > 1 ]; then
  31. #  echo Too many arguments
  32. #  echo Usage: $0 [config file]
  33. #  exit 1
  34. #fi
  35.  
  36.  
  37. # Does file exist?
  38. if [ ! -r $CHASSIS_FILE ]; then
  39.     echo File does not exist: $CHASSIS_FILE
  40.     exit 0;
  41. fi
  42.  
  43.  
  44. # Which services should be enabled based on chassis configuration?
  45. SHALL_TELNET_ENABLE=1
  46. SHALL_RSTAT_ENABLE=`$GREP "^rpc.rstatd:" $CHASSIS_FILE | $CUT -d':' -f2`
  47. SHALL_RUSERS_ENABLE=`$GREP "^rpc.rusersd:" $CHASSIS_FILE | $CUT -d':' -f2`
  48.  
  49. # Edit /etc/inetd.conf, looking for lines which refer to the first parameter
  50. # and update them according to the second parameter
  51. update_inetd_conf(){
  52.     umask 022
  53.     WS=$'[ \t]'           # WhiteSpace
  54.     ARG=${1//\//\\/}    # Replace / with \/ in $1 and assign to ARG
  55.     # if the service (telnet or rstat or rusers) is ON (uncommented)
  56.     # AND we want it off ($2 == 0) then comment it out.
  57.     if $GREP "^$1${WS}" /etc/inetd.conf >/dev/null ; then
  58.         if [ "$2" == 0 ] ; then
  59.             $SED -e "s/^$ARG${WS}/#&/" /etc/inetd.conf > /etc/inetd.conf.tmp &&
  60.             mv -f /etc/inetd.conf.tmp /etc/inetd.conf
  61.             echo "Updated inetd.conf to Disable $1 in inetdUpdate.sh"
  62.             RESTART_INETD=1
  63.         fi
  64.     else
  65.         if [ "$2" == 1 ] ; then
  66.             $SED -e "/^#$ARG${WS}/s/#//" /etc/inetd.conf > /etc/inetd.conf.tmp &&
  67.             mv -f /etc/inetd.conf.tmp /etc/inetd.conf
  68.             echo "Updated inetd.conf to Enable $1 in inetdUpdate.sh"
  69.             RESTART_INETD=1
  70.         fi
  71.     fi
  72. }
  73.  
  74. # Update Telnet in inetd.conf as neccessary
  75. update_inetd_conf telnet $SHALL_TELNET_ENABLE
  76.  
  77. # Update rstatd in inetd.conf as neccessary
  78. update_inetd_conf rstatd/1-3 $SHALL_RSTAT_ENABLE
  79.  
  80. # Update rusersd in inetd.conf as neccessary
  81. update_inetd_conf rusersd/1 $SHALL_RUSERS_ENABLE
  82.  
  83. # inetd.conf has been changed. Restart the daemon.
  84. if [ "$RESTART_INETD" == "1" ]; then
  85.     $KILLALL -q -HUP $INETD_PROC >/dev/null 2>&1
  86.  
  87.     if [ "$SHALL_TELNET_ENABLE" == "0" ]; then
  88.         # Kill all existing telnet sessions
  89.         for telpid in `$NETSTAT -tp | $GREP "telnet" | $GREP "ESTAB" | $SED -e 's/    +/ /g' |
  90.                        $SED -e 's/  */ /g' | $CUT -d' ' -f7 | $CUT -d'/' -f1`
  91.         do
  92.             logpid=`$PS -ef | $GREP $telpid | $GREP login | $SED -e 's/    +/ /g' |
  93.                     $SED -e 's/  */ /g' | $CUT -d' ' -f2`
  94.             $KILL $logpid
  95.         done
  96.     fi
  97. fi
  98.