I have a **bash script to setup UFW with an expected output as follows:
user@host:~$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22/tcp LIMIT IN Anywhere
80/tcp ALLOW IN Anywhere
443/tcp ALLOW IN Anywhere
22/tcp (v6) LIMIT IN Anywhere (v6)
80/tcp (v6) ALLOW IN Anywhere (v6)
443/tcp (v6) ALLOW IN Anywhere (v6)
I created a test function to verify the output is as expected. I copied the ouput manually into a variable and stored the output in another variable so i could compare the 2 as follows :
function test() {
# Verify that output is as excpeted
local output="$(sudo ufw status verbose)"
local expected="Status: active Logging: on (low) Default: deny (incoming), allow (outgoing), disabled (routed) New profiles: skip To Action From -- ------ ---- 22/tcp LIMIT IN Anywhere 80/tcp ALLOW IN Anywhere 443/tcp ALLOW IN Anywhere 22/tcp (v6) LIMIT IN Anywhere (v6) 80/tcp (v6) ALLOW IN Anywhere (v6) 443/tcp (v6) ALLOW IN Anywhere (v6)"
# echo
# echo $output
# echo
# echo $expected
# echo
if [[ "$output" == "$expected" ]]; then
echo "UFW setup: output was as expected"
else
echo "UFW setup: output NOT as expected!"
echo "Please check UFW status before coninuing:"
echo
sudo ufw status verbose
fi
Output:
luc@E580-debian:~$ test
UFW setup: output NOT as expected!
Please check UFW status before coninuing:
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22/tcp LIMIT IN Anywhere
80/tcp ALLOW IN Anywhere
443/tcp ALLOW IN Anywhere
22/tcp (v6) LIMIT IN Anywhere (v6)
80/tcp (v6) ALLOW IN Anywhere (v6)
443/tcp (v6) ALLOW IN Anywhere (v6)
As far as i know they are exactly the same, but I also dont know if there is a way to check if hidden characters are causing this. Or maybe if there is a way to remove/replace them.