telnet01.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/sh
  2. # Copyright (c) International Business Machines Corp., 2000
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. # the GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # 03/01 Robbie Williamson (robbiew@us.ibm.com)
  19. TCID="telnet01"
  20. TST_TOTAL=1
  21. TST_USE_LEGACY_API=1
  22. . tst_net.sh
  23. setup()
  24. {
  25. tst_require_cmds telnet expect
  26. if [ -z $RUSER ]; then
  27. RUSER=root
  28. fi
  29. if [ -z $PASSWD ]; then
  30. tst_brkm TCONF "Please set PASSWD for $RUSER."
  31. fi
  32. if [ -z $RHOST ]; then
  33. tst_brkm TCONF "Please set RHOST."
  34. fi
  35. if [ -z $LOOPCOUNT ]; then
  36. LOOPCOUNT=25
  37. fi
  38. }
  39. do_test()
  40. {
  41. tst_resm TINFO "Starting"
  42. for i in $(seq 1 ${LOOPCOUNT})
  43. do
  44. telnet_test || return 1
  45. done
  46. }
  47. telnet_test()
  48. {
  49. tst_resm TINFO "login with telnet($i/$LOOPCOUNT)"
  50. expect -c "
  51. spawn telnet $RHOST
  52. expect -re \"login:\"
  53. send \"$RUSER\r\"
  54. expect -re \"Password:\"
  55. send \"$PASSWD\r\"
  56. expect {
  57. \"incorrect\" {
  58. exit 1
  59. } \"$RUSER@\" {
  60. send \"LC_ALL=C ls -l /etc/hosts | \\
  61. wc -w > $RUSER.$RHOST\rexit\r\";
  62. exp_continue}
  63. }
  64. " > /dev/null || return 1
  65. tst_resm TINFO "checking telnet status($i/$LOOPCOUNT)"
  66. tst_rhost_run -u $RUSER -c "grep -q 9 $RUSER.$RHOST" || return 1
  67. tst_rhost_run -u $RUSER -c "rm -f $RUSER.$RHOST"
  68. }
  69. setup
  70. do_test
  71. if [ $? -ne 0 ]; then
  72. tst_resm TFAIL "Test $TCID failed."
  73. else
  74. tst_resm TPASS "Test $TCID succeeded."
  75. fi
  76. tst_exit