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 / cliexec / killtelnet < prev    next >
Text File  |  2010-11-10  |  3KB  |  98 lines

  1. #!/bin/bash
  2. #
  3. # Function to display/select/kill a session
  4. #
  5. LOC_FILE="/tmp/wout.`/bin/date +\"%s\"`"
  6. TR=/usr/bin/tr
  7. CUT=/usr/bin/cut
  8.  
  9. killSession() {
  10.     i=$1
  11.     /sbin/fuser -v /dev/${t_a[i]} >${LOC_FILE}
  12.     fuserResult=$?
  13.     if [ $fuserResult -ne 0 ]
  14.         then
  15.         printf "\nPermission Denied! Bailing Out!\n"
  16.         exit
  17.     fi
  18.  
  19.     printf "\n______________________________________________________________________________\n"
  20.     printf " USER     TTY      IDLE     LOGIN@ FROM\n"
  21.     printf "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
  22.     printf " %-8.12s %-8.12s %-8.12s %-6.12s %-16.128s\n" \
  23.         "${u_a[i]}" "${t_a[i]}" "${i_a[i]}" "${l_a[i]}" "${f_a[i]}"
  24.     printf "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
  25.     printf "Confirm Kill Session (Y/[N]): "
  26.     read choice
  27.     case $choice in
  28.         (Y|y|Yes|yes|YES) printf "\nKilling Session...."
  29.         /sbin/fuser -k -9 /dev/${t_a[i]} 1>/dev/null 2>&1
  30.         printf "  Done!\n"
  31.         ;;
  32.         (*)printf "NOT confirmed - No action taken\n" exit ;;
  33.     esac
  34. }
  35.  
  36. # Function to list a list of sessions showing marks, if any
  37. listSessions() {
  38.     if [ $SessionsCount -eq 0 ]
  39.         then
  40.         printf "No sessions found!\n"
  41.         exit
  42.     fi
  43.     printf "\n\n                   List of sessions (%d found)\n" $SessionsCount
  44.     printf "______________________________________________________________________________\n"
  45.     printf " Session No   USER     TTY      IDLE     LOGIN@ FROM\n"
  46.     printf "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
  47.     typeset -i i=0 SessionCount
  48.     while [ $i -lt $SessionsCount ]
  49.       do
  50.       printf " %5d        %-8.12s %-8.12s %-8.12s %-6.12s %-16.128s\n" \
  51.           $i  "${u_a[i]}" "${t_a[i]}" "${i_a[i]}" "${l_a[i]}" "${f_a[i]}"
  52.       i=i+1
  53.     done
  54.     printf "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
  55. }
  56.  
  57. #
  58. # Function to get the sessions and store them in an arry
  59. #
  60.  
  61. getSessions() {
  62.     printf "\nCollecting login information...."
  63.     typeset -i i=0 
  64.     /usr/bin/w -f > ${LOC_FILE}
  65.  
  66.     {
  67.         read uptime_details
  68.         read column_headers
  69.         while read u_a[$i] t_a[$i] f_a[$i] l_a[$i] i_a[$i] j_a[$i] p_a[$i] c_a[$i]
  70.             do
  71.             i=i+1
  72.         done 
  73.     } < ${LOC_FILE}
  74.  
  75.     SessionsCount=$i
  76. }
  77.  
  78. # main starts here (keep bugging the user until s/he decides to quit)
  79.  
  80. while :
  81.     do
  82.     getSessions
  83.     listSessions
  84.     printf "\nEnter Session Number to terminate (q to quit) "
  85.     read choice
  86.     case $choice in
  87.         (Q|q) exit ;;
  88.         (""|*[!0-9]*) printf "Please enter a number\n" >&2 ;;
  89.         (*)
  90.         if [ $choice -lt 0 -o $choice -ge $SessionsCount ]
  91.         then
  92.             printf "Please enter a value between 0 and $((SessionCount-1))\n"
  93.         else
  94.             killSession $choice
  95.         fi
  96.     esac
  97. done # main while
  98.