I'm in the process to enable the firewall on a VM. Initially the firewall is in a masked state. I use two functions
function status_firewall() {
RET_VAL=" "
STATUS=$(systemctl status firewalld)
MASKED=$(grep -e "masked" <<< $STATUS)
M_RET=$?
DEAD=$(grep -e "dead" <<< $STATUS)
D_RET=$?
logging "M_RET and D_RET: $M_RET, $D_RET"
if [ "${M_RET}" -eq "0" ]; then
RET_VAL=1
elif [ "${D_RET}" -eq "0" ]; then
RET_VAL=2
else
RET_VAL=0
fi
echo ${RET_VAL}
}
echo statement prints value "1" if firewall is masked
function check_firewall() {
FIREWALL=$(status_firewall)
logging "Firewall status in check_firewall: ${FIREWALL}"
if [ "$(status_firewall)" -eq "0" ]; then
logging "Firewalld service already running"
RET_VAL=0
elif [ "$(status_firewall)" -eq "1" ]; then
...
elif
...
fi
I get the correct MASKED and DEAD status value (0, 0) status_firewall() { ... } However, when checking for the return values in check_firewall() { .. } I get the following integer error: integer expression expected
When checking the return value in: check_firewall() it lists: Firewall status: ● firewalld.service Loaded: masked (/dev/null) Active: inactive (dead)
How come the first function supposedly returns value "1" but in the second function it lists the return value as the output of the command: systemctl status firewalld
$FIREWALL.loggingdo?return 0on success and then justif status_firewall; then ...-eqcompares two integers.=compares two strings.