I have at my ubuntu server an iptables based firewall, which is running good. Now I want to see (echo) at my screen (CLI) certain related output. F.i. I give some persons access through port 22 and want to echo their names and ip in the CLI (when I run the firewall). Let's say:
peter="123.456.78.90"
mike="123.456.78.91"
port_ssh="22"
access-port-ssh="$peter $mike"
Using the firewall code, this is all ok and they have access through port 22. I just want to echo a line in the CLI, which shows:
IP 123.456.78.90 (peter) has access to server, port 22
and during the next run of the loop in my firewall:
IP 123.456.78.91 (mike) has access to server, port 22
The only thing I want to know is how do I get the name "peter" nad "mike" at my screen since the rest I know. The loop is as follows, and the question is: which code should I use to replace the "XXXX" (in second-last line) by "peter" and next run by "mike"
ALLOWED=access-port-ssh; ALLOWED_IPS=${!ALLOWED}
for IP in ${ALLOWED_IPS}; do
${IPTABLES} -A INPUT -i ${LAN_IFACE} -p tcp -s ${IP} --dport ${port-ssh} --sport ${port-ssh} -j ACCEPT
${IPTABLES} -A OUTPUT -o ${LAN_IFACE} -p tcp -d ${IP} --sport ${port-ssh} --dport ${port-ssh} -j ACCEPT
echo "${IP} (XXXX) has access to server, port: ${port-ssh}"
done
Edit post to make it more clear (without the whole context): how can I echo the variable names ("peter" and "mike"), when using only variable "access-port-ssh". I tried:
peter="123.456.78.90"
mike="123.456.78.91"
access="$peter $mike"
allowed=access; allowed=${!allowed}
for i in ${allowed}; do variable_name=(${!i@}); echo $variable_name; done