#ident "@(#)/usr/local/sysadmin/GENADMIN 1.0 03/18/91" Author: Mr Reinhard Pfaffinger
# Office: 1924 CSS/SDA, Randolph AFB, Texas 78150
# Phone: AV 487-8649  Comm: (512) 652-8649
#
# This script allows a system administrator to perform miscellaneous system
# administration functions.
#

chkfortty() {
             if [ "$TERM" = "tty" ]
               then
                   echo  
             else
                 tput clear 
             fi
            }

rtn() {
        echo "\nPress <RETURN> ... \c"
        read RTN
      }

chkcron() {
           FLAG=""
           CRONTHERE="`ps -ef | fgrep /etc/cron | fgrep -v 'fgrep /etc/cron' | cut -c48-56`"
           if [ -z "$CRONTHERE" ]
             then
                 FLAG="down"
           else
               FLAG="up"
           fi
          }           

EDIT() {
        chkfortty
        echo "Which TEXT EDITOR would you like: 'vi' or 'fred'? v/f <RETURN> =>> \c"
        read EDT
        case "$EDT" in
           v|V)
               vi $1
               ;;
           f|F)
               /usr/local/fred $1
               ;;
           *)
             echo "\nAssuming 'vi' ... \c"
             sleep 2
             vi $1
             ;;
        esac
       }

while :
 do
   chkfortty
   echo "            <<< AT&T 3B2/600G General System Administration Menu >>>\n"
   echo "                	1. PRELUDE Administration" 
   echo "                	2. CRON Management" 
   echo "	              	3. Monitor System Performance"
   echo "			4. Show Logged-In User Processes"
   echo "			5. View System Error Logs"
   echo "			6. Hexadecimal/Octal File Dump\n"
   echo "                	q or Q to quit\n"
   echo "                	Enter response <RETURN> =>> \c"
   read RESP
   case "$RESP" in
      1)
        chkfortty
        pradmin
        continue
        ;;
      2)
        while :
         do
        chkfortty
        echo "\t\t\tSelect one of the following options:\n"
        echo "\t\t\t\t1. Shut Down CRON"
        echo "\t\t\t\t2. Start Up CRON"
        echo "\t\t\t\t3. CRON Process Status"
        echo "\t\t\t\t4. Modify CRONTAB File(s)"
        echo "\t\t\t\t5. Modify CRON.ALLOW File"
        echo "\t\t\t\t6. View CRON Log File\n"
        echo "\t\t\t\tq or Q to quit\n"
        echo "\t\t\tEnter response <RETURN> =>> \c"
        read CRONRSP 
        case "$CRONRSP" in
           1)
             chkfortty
             chkcron
             if [ "$FLAG" = "up" ]
               then
                   /usr/local/killpid cron
             else
                 echo "\n\t\t'cron' is not running!\c"
                 sleep 3; echo
             fi
             rtn
             ;;
           2)
             chkfortty
             chkcron
             if [ "$FLAG" = "down" ]
               then
                   echo "Starting up CRON ... \n"
                   /etc/cron
                   ps -ef | fgrep /etc/cron | fgrep -v "fgrep /etc/cron"
             else
                 echo "\n\t\t'cron' is already running!\c"
                 sleep 3; echo
             fi
             rtn
             ;;
           3)
             chkfortty
             echo "CRON process status ... \n"
             ps -ef | fgrep /etc/cron | fgrep -v "fgrep /etc/cron"
             rtn
             ;;
           4)
             PREVDIR=`pwd`
             chkfortty
             echo "These are the CRONTAB file(s) you may modify:\n"
             cd /usr/spool/cron/crontabs
             ls -x  
             echo "\nWhich file do you wish to modify? <RETURN> =>> \c"
             read CRONFILE
             if [ -f "$CRONFILE" ]
               then 
                   EDIT $CRONFILE
             else
                 echo "\n'$CRONFILE' does not exist!\c"
                 sleep 3
             fi
             cd $PREVDIR
             ;;
           5)
             EDIT /usr/lib/cron/cron.allow
             ;;
           6)
             chkfortty
             pg -n21 -p"Press <RETURN> to continue; q or Q to quit ... " /usr/lib/cron/log
             ;;
         q|Q)
             break;;
           *)
             echo "\n\t\t\t\tInvalid response!\c"
             sleep 2
             continue
             ;;
        esac
         done
        continue
        ;;
      3)
        chkfortty 
        /usr/local/pmon
        continue
        ;;
      4)
        chkfortty 
        echo "\t\t\tSelect one of the following:\n"
        echo "\t\t\t\t1. WHODO"
        echo "\t\t\t\t2. Users\n"
        echo "\t\t\t\tq or Q to quit\n"
        echo "\t\t\tEnter response <RETURN> =>> \c"
        read RESP
        case "$RESP" in
           1)
             chkfortty 
             /etc/whodo | pg -n21 -p"Press <RETURN> to continue; q or Q to quit ... "
             ;;
           2)
             while :
              do
             chkfortty 
             echo "Enter user ID for user whose processes you wish to see <RETURN> =>> \c"
             read GETUSR
             if [ "$GETUSR" = "" ]
               then
                   chkfortty 
                   echo "Showing all user processes ... \n"
                   /usr/local/users | pg -n22 -p"Press <RETURN> to continue; q or Q to quit ... "
                   break
             else
                 GDUSR=`egrep "^$GETUSR:" /etc/passwd`
                 if [ "$GDUSR" = "" ]
                   then
                       echo "\n\t\tInvalid user ID!\c"
                       sleep 3
                 else
                     /usr/local/users $GETUSR | pg -n22 -p"Press <RETURN> to continue; q or Q to quit ... "
                     break
                 fi
             fi
              done
             ;;
        esac
        continue
        ;;
      5)
        chkfortty
        echo "\t\t\tSelect one of the following:\n"
        echo "\t\t\t1. System Error Log"
        echo "\t\t\t2. System Core Dump Error Log"
        echo "\t\t\t3. SU Log"
        echo "\t\t\t4. Failed Login Attempts Log\n"
        echo "\t\t\tq or Q to quit\n"
        echo "\t\t\tEnter response <RETURN> =>> \c"
        read RESP
        case "$RESP" in
           1)
             chkfortty
             /etc/errint | pg -n22 -p"Press <RETURN> to continue; q or Q to quit ... "
             rtn
             ;;
           2)
             chkfortty
             /etc/errdump | pg -n22 -p"Press <RETURN> to continue; q or Q to quit ... "
             rtn
             ;;
           3)
             /usr/local/sulog
             ;;
           4)
             /usr/local/printllog
             ;;
        esac
        continue
        ;;
      6)
        while :
         do
        chkfortty
        echo "\t\t\tSelect one of the following:\n"
        echo "\t\t\t1. Hexadecimal File Dump"
        echo "\t\t\t2. Octal File Dump\n"
        echo "\t\t\tq or Q to quit\n"
        echo "\t\t\tEnter response <RETURN> =>> \c"
        read RESP
        case "$RESP" in
           1)
             chkfortty
             echo "Enter the name of the file you wish to dump <RETURN> =>> \c"
             read FL
             if [ -r "$FL" ]
               then
                   chkfortty
                   /usr/local/hd $FL | pg -n22 -p"Press <RETURN> to continue; q or Q to quit ... "
                   rtn
             else
                 echo "\n\t\tCannot read '$FL'!\c"
                 sleep 3
             fi
             ;;
           2)
             chkfortty
             echo "Enter the name of the file you wish to dump <RETURN> =>> \c"
             read FL
             if [ -r "$FL" ]
               then
                   chkfortty
                   /bin/od $FL | pg -n22 -p"Press <RETURN> to continue; q or Q to quit ... "
                   rtn
             else
                 echo "\n\t\tCannot read '$FL'!\c"
                 sleep 3
             fi
             ;;
         "")
            break;;
         q|Q)
             break;;
        esac
         done
        continue
        ;;
    q|Q)
        exit 0
        ;;
      *)
        echo "\n\t\t\t\tInvalid response!\c"
        sleep 2
        continue
        ;;
   esac
 done
