【发布时间】:2021-12-30 03:21:28
【问题描述】:
我有一个for循环如下:
mapfile -t ipLast < SippIPs.txt
echo " ---- SIPp ---- "
echo "Please give count of SIPps needed to generate calls.."
read -p 'Sipps count starts from: ' start; read -p 'Sipps count ends on: ' end
if [[ -z $start ]] || [[ -z $end ]]; then echo "User pressed ENTER with no input text"; fi
for ((j=$start; j<=$end; j++)); do
sipps=${j[@]}
ipList=(${ipLast[sipps-1]})
if [[ "$end" -eq 0 ]]; then
echo "No way it cannot end on 0"
exit
fi
echo " ---- Launching SIPp $sipps ---- "
sshpass -p "root12" ssh -tt -o StrictHostKeyChecking=no root@$ipList <<EOF1
pkill -f sipp
screen -S sipp -d -m bash -c 'cd /usr/local/src/sipp-3.3; ulimit -Hn 65535; ulimit -Sn 65535; ./sipp -i $ipList -mi $ipList -sf HA_demo.xml -inf HA_demo.csv 10.171.0.231:5060 -p 5060 -r 1 -rp 1s -l 1 -m 1 -watchdog_minor_threshold 1500 -watchdog_major_threshold 4000 -watchdog_major_maxtriggers 30 -trace_err -aa -d 350s -oocsn ooc_default -t u1 -trace_screen -skip_rlimit && exec bash'
exit
EOF1
done
我想将 for 循环转换为 while 循环,以便在给出计数后返回到循环以询问用户是要退出还是继续启动 SIPp。
我的尝试:
mapfile -t ipLast < SippIPs.txt
read -p 'Sipps count starts from: ' start; read -p 'Sipps count ends on: ' end
j=$start
while (j<=$end); do
sipps=${j[@]}
ipList=(${ipLast[sipps-1]})
if [[ "$end" -eq 0 ]]; then
echo "No way it cannot end on 0"
exit
fi
echo " ---- Launching SIPp $sipps ---- "
sshpass -p "root12" ssh -tt -o StrictHostKeyChecking=no root@$ipList <<EOF1
pkill -f sipp
screen -S sipp -d -m bash -c 'cd /usr/local/src/sipp-3.3; ulimit -Hn 65535; ulimit -Sn 65535; ./sipp -i $ipList -mi $ipList -sf HA_demo.xml -inf HA_demo.csv 10.171.0.231:5060 -p 5060 -r 1 -rp 1s -l 1 -m 1 -watchdog_minor_threshold 1500 -watchdog_major_threshold 4000 -watchdog_major_maxtriggers 30 -trace_err -aa -d 350s -oocsn ooc_default -t u1 -trace_screen -skip_rlimit && exec bash'
exit
j++
EOF1
done
【问题讨论】:
标签: bash while-loop