I am trying to execute this script, but it's not working.
My requirement is with the help of curl command we will get the connection results. In that results http code is connected:200 , then return success or else trigger a alert to specified mail.
#/bin/bash
status=curl-v-u Administrator:****** https://(server address :5555)
if grep -q connected:200 "$status";
then
echo "success"
else
echo "Server is down" | mailx -s "server is down" ******@gmail.com
-f
Thanks much in advance :)
Error message:
CodePudding user response:
Rather than the rather bland "success", just let the output of the curl be visible. eg:
#/bin/bash
if ! curl -v -u 'Administrator:******' https://"$addr":5555 | grep connected:200; then
echo "Server is down" | mailx -s "server is down" "******@gmail.com"
echo "Server is down" >&2
fi
CodePudding user response:
nc -v -z 10.10.1.2 80 2>&1 | grep succeeded | wc -w
This will return 0 if port 80 does not have anything listening.