Answer the question
In order to leave comments, you need to log in
[[+content_image]]
How to load curl or wget response into variable and compare in condition?
You need to "intercept" responses from web servers and assign your own "beautiful" error responses.
I do it like this:
request=`curl -Is -u $2:$3 $1 | head -1`
if [[ "$request" == *200* ]]
then
echo "Everything is OK!"
echo "Everything is OK!" >> ./script.log
fi
if [[ "$request" == *403* ]]
then
echo "ERROR: Cannot connect to $1: 403"
echo "ERROR: Cannot connect to $1: 403" >> ./script.log && exit
fi
request=`wget -q --user=$2 --password=$3 $1 | head -1`
if [[ "$request" == *error* ]] # - где error это предполагаемое содержимое заголовка
then
echo "ERROR: Cannot connect to $1: site $1 doesn't exist"
echo "ERROR: Cannot connect to $1: site $1 doesn't exist" >> ./script.log && exit
fi
request1=`ping -q -c 1 $1 | /dev/null`
wget $1 2>/dev/null
export RC=$?
if [ "$RC" = "0" ];
then echo $1 OK
else echo $1 FAILED
fi
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question