ssh-stress02-rmt.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
  3. # Copyright (c) International Business Machines Corp., 2005
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License as
  7. # published by the Free Software Foundation; either version 2 of
  8. # the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it would be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write the Free Software Foundation,
  17. # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. #
  19. # Author: Mitsuru Chinen <mitch@jp.ibm.com>
  20. #
  21. TCID="ssh_stress02_rmt"
  22. TST_TOTAL=1
  23. . test.sh
  24. # Check the arguments
  25. if [ $# -ne 5 ]; then
  26. tst_brkm TBROK "Usage: $0 ipver rhost config connections duration"
  27. fi
  28. ip_ver="$1"
  29. server_ipaddr="$2"
  30. ssh_config="$3"
  31. connections="$4"
  32. duration="$5"
  33. ssh -$ip_ver -F $ssh_config $server_ipaddr \
  34. "true < /dev/null > /dev/null 2>&1" > /dev/null
  35. [ $? -ne 0 ] && tst_brkm TBROK "Failed to connect '$server_ipaddr'"
  36. start_epoc=$(date +%s)
  37. while true ; do
  38. # Exit when the specified seconds have passed.
  39. current_epoc=$(date +%s)
  40. elapse_epoc=$(($current_epoc - $start_epoc))
  41. [ $elapse_epoc -ge $duration ] && break
  42. # Do not make ssh connection over the specified quantity
  43. ssh_num=$(jobs | wc -l)
  44. if [ $ssh_num -ge $connections ]; then
  45. sleep 1
  46. continue;
  47. fi
  48. # specified wait time and login time
  49. wait_sec=$(($(od -A n -d -N 1 /dev/random) * 3 / 255))
  50. login_sec=$(($(od -A n -d -N 1 /dev/random) * 10 / 255))
  51. # Login to the server
  52. (sleep $wait_sec ; ssh -$ip_ver -F $ssh_config -l root $server_ipaddr \
  53. "sleep $login_sec < /dev/null > /dev/null 2>&1") > \
  54. /dev/null 2>&1 &
  55. done
  56. # wait for the finish of all process
  57. wait
  58. # Check the connectivity again
  59. ssh -$ip_ver -F $ssh_config $server_ipaddr \
  60. "true < /dev/null > /dev/null 2>&1" > /dev/null
  61. [ $? -ne 0 ] && tst_brkm TBROK "Failed to connect '$server_ipaddr'"
  62. tst_exit