my goal is to store each foliated line (actually each rule) into an array. My output:
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT udp -- 109.224.241.0/24 0.0.0.0/0 udp dpt:5060
2 ACCEPT udp -- 109.224.241.0/24 0.0.0.0/0 udp dpt:4569
3 ACCEPT udp -- 217.14.138.0/24 0.0.0.0/0 udp dpt:5060
4 ACCEPT udp -- 217.14.138.0/24 0.0.0.0/0 udp dpt:4569
5 ACCEPT udp -- 172.30.33.0/24 0.0.0.0/0 udp dpt:5060
6 ACCEPT udp -- 172.30.33.0/24 0.0.0.0/0 udp dpt:4569
7 ACCEPT udp -- 212.11.91.0/24 0.0.0.0/0 udp dpt:5060
8 ACCEPT udp -- 212.11.91.0/24 0.0.0.0/0 udp dpt:4569
9 ACCEPT udp -- 212.11.64.0/19 0.0.0.0/0 udp dpt:5060
10 ACCEPT udp -- 212.11.64.0/19 0.0.0.0/0 udp dpt:4569
11 ACCEPT udp -- 77.240.48.0/20 0.0.0.0/0 udp dpt:5060
12 ACCEPT udp -- 77.240.48.0/20 0.0.0.0/0 udp dpt:4569
13 LOG udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:4569 LOG flags 0 level 4 prefix "AsteriskHack:"
14 DROP udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:4569
15 LOG udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:5060 LOG flags 0 level 4 prefix "AsteriskHack:"
16 DROP udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:5060
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
I do not want to limit rule number. Each chains has several rules.
After I executed my code.:
while IFS='' read line -r || [[ -n "$line" ]]; do
array+=($line)
done < <(iptables -L --line-numbers)
When I echo ${array[@]}
my output is horrible text in one line, so I would like to seperate each line. Actually my content of this array consists of unreal number of iptables rules (after echo ${!array[@]}
)
I do not know how to have in conditional that foliated rows are compulsory with defined separator (new line). I am not sure if is my separator right.
Thank you for your reply, M
read line -r line
typo?