Hey guys,
Can't find the error in my nested if/else. Please help.
error I get is -
line 56: syntax error near unexpected token `then'
line 56: `else [ "$LOCATION" = "HomeFi" ]; then'
LOCATION=$(networksetup -getcurrentlocation)
if [ "$LOCATION" = "Rental" ]; then
host google.com 192.168.2.1 >/dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e " Internet (Networking Infrastructure) \t\t [${red} DOWN ${normal}]"
else
echo -e " Internet (Networking Infrastructure) \t\t [${green} OK ${normal}]"
fi
elif [ "$LOCATION" = "Office" ]; then
host google.com 172.16.160.50 >/dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e " Internet (Networking Infrastructure) \t\t [${red} DOWN ${normal}]"
else
echo -e " Internet (Networking Infrastructure) \t\t [${green} OK ${normal}]"
fi
elif [ "$LOCATION" = "Home" ]; then
host google.com 172.16.173.65 >/dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e " Internet (Networking Infrastructure) \t\t [${red} DOWN ${normal}]"
else
echo -e " Internet (Networking Infrastructure) \t\t [${green} OK ${normal}]"
fi
else [ "$LOCATION" = "HomeFi" ]; then
host google.com 172.16.173.65 >/dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e " Internet (Networking Infrastructure) \t\t [${red} DOWN ${normal}]"
else
echo -e " Internet (Networking Infrastructure) \t\t [${green} OK ${normal}]"
fi
fi
Can't find the error in my nested if/else. Please help.
error I get is -
line 56: syntax error near unexpected token `then'
line 56: `else [ "$LOCATION" = "HomeFi" ]; then'
LOCATION=$(networksetup -getcurrentlocation)
if [ "$LOCATION" = "Rental" ]; then
host google.com 192.168.2.1 >/dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e " Internet (Networking Infrastructure) \t\t [${red} DOWN ${normal}]"
else
echo -e " Internet (Networking Infrastructure) \t\t [${green} OK ${normal}]"
fi
elif [ "$LOCATION" = "Office" ]; then
host google.com 172.16.160.50 >/dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e " Internet (Networking Infrastructure) \t\t [${red} DOWN ${normal}]"
else
echo -e " Internet (Networking Infrastructure) \t\t [${green} OK ${normal}]"
fi
elif [ "$LOCATION" = "Home" ]; then
host google.com 172.16.173.65 >/dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e " Internet (Networking Infrastructure) \t\t [${red} DOWN ${normal}]"
else
echo -e " Internet (Networking Infrastructure) \t\t [${green} OK ${normal}]"
fi
else [ "$LOCATION" = "HomeFi" ]; then
host google.com 172.16.173.65 >/dev/null 2>&1
if [ "$?" != 0 ]; then
echo -e " Internet (Networking Infrastructure) \t\t [${red} DOWN ${normal}]"
else
echo -e " Internet (Networking Infrastructure) \t\t [${green} OK ${normal}]"
fi
fi