Reputation: 57
I am using for loops in bash to loop over an array of IPs from file. There are around 38 IPs and in one file and I want to select any range of IP like for example I should be able to loop over if a user asks to go for IP address from range 10 to 20. But with the for loop I am not able to find out how to use seq or give a range. Below is an example:
mapfile -t ip < SippIPs.txt
echo
read -p 'How many Sipp's are required: ' choice
echo
for ((j=1; j<=$choice; j++)); do
sipps=${j[@]}
ips=(${ip[sipps-1]})
echo "$sipps"
echo "$ipList"
echo " ---- Launching SIPp $sipps ---- "
sshpass -p "root12" ssh -tt -o StrictHostKeyChecking=no root@$ips <<EOF1
screen -S sipp -d -m bash -c 'cd /usr/local/src/sipp-3.3; ulimit -Hn 65535; ulimit -Sn 65535; ./sipp -i $ips -mi $ips -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
Below is how my ips text file looks like:
[root@megahost23 MasterScript]# cat SippIPs.txt
10.171.0.201
10.171.0.202
10.171.0.203
10.171.0.204
10.171.0.205
10.171.0.206
10.171.0.207
10.171.0.208
10.171.0.209
10.171.0.210
10.171.0.211
10.171.0.212
10.171.0.213
10.171.0.214
10.171.0.215
Can someone guide please how can I give a range with the abovementioned for loop I am using?
Upvotes: 0
Views: 254
Reputation: 7922
How about something like this:
$ read -p 'min: ' min
min: 3
$ read -p 'max: ' max
max: 10
$ mapfile -t zumba < /tmp/range
$ for (( i=min-1; i <= max-1 ; i++ )) ; do echo ${zumba[i]}; done
c
d
e
f
g
h
i
j
Upvotes: 1