home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2606 < prev    next >
Encoding:
Text File  |  1992-11-23  |  1.9 KB  |  57 lines

  1. Organization: Carnegie Mellon, Pittsburgh, PA
  2. Path: sparky!uunet!cis.ohio-state.edu!news.sei.cmu.edu!fs7.ece.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!tm8t+
  3. Newsgroups: alt.sources
  4. Message-ID: <gf4Fu0O00WB7EcL1RX@andrew.cmu.edu>
  5. Date: Mon, 23 Nov 1992 13:10:08 -0500 
  6. From: Tod McQuillin <tm8t+@andrew.cmu.edu>
  7. Subject: Zap a user
  8. Lines: 47
  9.  
  10. Recently one of our (ever watchful for ways to improve efficiency)
  11. machine room operators came to me and asked if there was a way to
  12. automate the procedure of knocking users off the system.  Frequently
  13. people would call him and say "My terminal is frozen, can you kill all
  14. my proceses?".
  15.  
  16. Now, of course the correct procedure is probably to educate the users
  17. better, but there are a zillion of them and this isn't always
  18. practical.  So the operators are trained in this method:
  19.  
  20. Type who and see what tty the user is using.  Then do ps -txx and see
  21. the process list.  Then kill each process.  Needless to say this is
  22. time-consuming and boring, so I wrote a shell script to help him out.
  23.  
  24. It takes as an argument the tty on which to wreak havoc.  Then it
  25. presents a list of the processes running there and asks permission to
  26. zap them.
  27.  
  28. Granted, this doesn't score too many points in the way of hack value,
  29. and many of us I'm sure could write a similar script in 5 minutes, but
  30. for those who aren't so adept, this could serve as a valuable addition
  31. to the shell script library, so I posted it anyway.  At the very least
  32. it could serve as an educational example to people just learning shell
  33. programming.
  34.  
  35. -----Cut Here--------------------
  36. #!/bin/sh
  37.  
  38. echo "Killing all processes on /dev/tty$1"
  39. procs=`ps -t$1 | tail +2`
  40. echo "Kill these processes:
  41. $procs"
  42. while true; do
  43.   echo -n "Yes or no (Y/N)? "
  44.   read answer
  45.   case $answer in
  46.     [yY]*) kill -TERM `echo "$procs" | cut -c1-5`
  47.       exit 0
  48.       ;;
  49.     [nN]*) echo "Nothing was killed"
  50.       exit 0
  51.       ;;
  52.     *) echo "Unknown answer!"
  53.       ;;
  54.   esac
  55. done
  56.  
  57.