I am doing some bash scripting and would like to know how to recognize empty output or a specific string output when running a command in the bash script.
Example - If I perform a ping to google.com and due to no connectivity I get the message "No route to host", I would like the program to echo "You have done a boo boo".
What I have tried:
if [[ "$(ping -c 1 -n -q $address | grep -q 'ping: sendto: No route to
host')" > /dev/null ]];
then echo " Your server is up and working, please proceed to the next
step"
elif [-n "$(ping -c 1 -n -q $address | grep -q 'ping: sendto: No route
to host')" == *java* ];
then echo "Your server is down, please fix this issue"
else
echo "No response"
fi
Also, looked at other methods of achieving this but couldn't find a working solution.