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