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 / snmpKillTelnet < prev    next >
Text File  |  2010-11-10  |  2KB  |  87 lines

  1. #!/bin/sh
  2. #
  3. #    Copyright (c) 2003 Brocade Communications Systems, Inc.
  4. #    All rights reserved.
  5. #
  6. #    File name:   snmpKillTelnet
  7. #    Module name: fabos/src/snmp/src/snmpUtils.c
  8. #
  9. #    This script will terminate ALL/SPECIFIC telnet sessions on a switch.
  10. #    ALL telnet sessions option will also  logout the user from console.
  11. #
  12. #    Usage: snmpKillTelnet <Switch Ip Addr>
  13. #               { <switchInst> | <Remote Ip Addr> <Remote Port> }
  14. #
  15. #           <Switch Ip Addr> is ip addr in dot notation Ex: 10.32.227.10
  16. #           <SwitchInst> On a Ulysses is 0 or 1.  On a Terminator is 0.
  17. #           <Remote Ip Addr> is ip addr in dot notation Ex: 192.168.68.45
  18. #           <Remote Port Number> is a numeric. Ex: 4567
  19. #
  20.  
  21. export PATH=/fabos/sbin:/fabos/bin:/bin:/usr/bin:/sbin
  22.  
  23. #Error code 1
  24. shFailed=1
  25.  
  26. #No Error
  27. shSuccess=0
  28.  
  29. if [ $# -eq 2 ]; then
  30.     switchIp=$1
  31.     switchInst=switch$2
  32.  
  33.     pidList=`netstat -tnp | grep $switchIp:23 | grep ESTABLISHED |
  34.              cut -s -d: -f3 | sed -e 's/ //g' | cut  -s -d/ -f1 |
  35.              cut -s -dD -f2`
  36.     # Information for User
  37.     wall All Telnet sessions on $switchInst will be logged out.
  38.  
  39. elif [ $# -eq 3 ]; then
  40.     switchIp=$1
  41.     remoteIp=$2
  42.     remotePort=$3
  43.  
  44.     pidList=`netstat -tnp | grep $switchIp:23 | grep $remoteIp:$remotePort |
  45.              grep ESTABLISHED | cut -s -d: -f3 | sed -e 's/ //g' |
  46.              cut  -s -d/ -f1 | cut -s -dD -f2`
  47. else
  48.     #echo Invalid number of arguments: $# returning $shFailed
  49.     exit $shFailed
  50. fi
  51.  
  52. # Loop through all 'pid' entries of telnet sessions
  53. for pid in $pidList
  54. do
  55.     if test "$pid" = ""
  56.     then
  57.         #echo "Error: Could not find any telnet session."
  58.         exit $shFailed
  59.     fi
  60.  
  61.     kill -9 $pid > /dev/null
  62. done
  63.  
  64. #Logout the user from console ttyS0
  65. switchTty=ttyS0
  66.  
  67. if [ $# -eq 2 ]; then
  68.     for tty in `w -hs | sed -e 's/root/switch/g' | sed -e 's/factory/switch/g' |
  69.                 sed -e 's/admin/switch/g' | sed -e 's/user/switch/g' |
  70.                 grep $switchTty | sed -e 's/    / /g' | sed -e 's/   / /g' |
  71.                 sed -e 's/  / /g' | grep $switchInst | cut -d' ' -f2`
  72.     do
  73.         #Information for user.
  74.         wall $switchTty on switch instance $switchInst will be logged out
  75.         pid=`fuser /dev/$tty | sed -e "s,^/dev/[[:alnum:]/]*:[[:space:]]*,,g"`
  76.         if test "$pid" = ""
  77.         then
  78.             #echo "Error: Could not find sh or rbash for" $tty"."
  79.             exit $shFailed
  80.         fi
  81.  
  82.         kill -9 $pid > /dev/null
  83.     done
  84. fi
  85.  
  86. exit $shSuccess
  87.