• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

Bash script failing

Dear experts,

below is a bash script to check if exchange owa web site is reachable or not, but it seems to be it doesn't find the string "*utlook*" in the source of owa page. I'm getting all the time as result "failure". Does someone why please?
----------
#!/bin/bash
LINES=`wget –q –O - --no-check-certificate https://$1:$2/owa`
if [[ $LINES == *utlook* ]]; then
echo "OK"
else
echo "FAILURE"
fi
exit 0
--------
K rgs
0
DigitBoy
Asked:
DigitBoy
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
arnoldCommented:
Use grep in the test, better
If test 'echo "$LINES" | grep "pattern" 2>&1 >/dev/null' ; then
       echo match
else
       echo no match
fi

Check exit codes from wget.
I.e. check whether a socket can be established, check whether the http status response is 2xx then check for a specific value.

Alternatively, you could use curl to perform a transaction that will confirm that the sites both responsive and functional.
0
 
TintinCommented:
Use

if wget –q –O - --no-check-certificate https://$1:$2/owa | grep -q utlook
then
      echo OK
else
     echo FAILURE
fi

Open in new window

0
 
savoneCommented:
The reason this is failing is because your are testing against the output of the wget command and not the source of the page.

Run this script to see what I mean:

LINES=`wget http://aivila.com`
echo $LINES

Open in new window


You can test the exit code of the wget command like so:

TEST=`wget --timeout=10 -q $1`
if [ $? -eq 0 ]; then
echo got it!
else
echo NOPE
fi

Open in new window

0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
DigitBoyAuthor Commented:
Dear experts,

thank you for your responses. I'm not coder at all. Can someone of you experts provide me more information regarding your codes please?
Maybe stupid question, but do I need modify your provided codes to run the test? Or can I copy & paste and run the codes?


K rgs
0
 
arnoldCommented:
You should first test to make sure the result you expect is the result you get.
You would then modify a copy of your script with the option that works to achieve your goal.
0
 
savoneCommented:
You can create a file called test.sh (or whatever you like) and copy and paste this script to try it:

LINES=`wget http://aivila.com`
echo $LINES

Open in new window


That will show you that you are testing against the output of the wget command, not the source of the page.

Then you can create a new script called healthcheck.sh (or whatever you like) and copy and paste the following code:

TEST=`wget --timeout=10 -q $1`
if [ $? -eq 0 ]; then
echo got it!
else
echo NOPE
fi

Open in new window


To run that script you have to pass it a website name on the command line like so:

./healthcheck.sh http://aivila.com
0
 
savoneCommented:
Of course after you create these files you have to make them executable too, like so:

chmod +x <filename>

(replace filename with whatever you named the file)
0
 
DigitBoyAuthor Commented:
Thanks a lot experts :-). Thanks to you guys it is working now.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now