I´m trying to understand a Linux Bash Script. The aim of the script is to limit the access to server services only for some dyndns users (by use of ufw rules). Part of the script:
ALLOWEDUSERS="client1.dyndns.org client2.dyndns.org"
for host in $ALLOWEDUSERS ; do
ip=`host $host | cut -d ' ' -f 4`
if [ $? -eq 0 ]; then
ufw allow proto tcp from $ip to any
fi
done
okay
for host in $ALLOWEDUSERS ; do
is clear, it loops through ALLOWEDUSERS,
as far as I understand
if [ $? -eq 0 ]; then
checks if the command executed before is true (if so the ufw rule is added)
but how does the rest of the snippet
ip=`host $host | cut -d ' ' -f 4`
checks if the client ip is the one from the allowed dyndns account?
thanks a lot for your help,
tony
hostcommand, which is0if the hostname lookup is successful. But it's actually checking the exit status ofcut, because the status of a pipeline is the status of the last command. So it doesn't work as intended.cutwill always return true in this case, henceufwwill always run. Oh dear.