Jump to content

Bash Shell, using wget and awk?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
TIGA

TIGA

    Newbie

  • Members
  • Pip
  • 1 posts
hi everybody,


i would like to ask questions regarding bash shell scripting.

but First let me introduce myself.

i am Tiga from amsterdam, and i am kind of new to the programming world.

i have been learning c++ and java.

ive also been using linux a lot lately, and writing lot of perl and bash scripts for my work and private use.

now lets get back to the question.

Question:

i have a function in bash shell that i want to use to check if the given url returns 200 response code or something else. and if the reponse code is 200 then the function should return value 0 for pass and if its anything other than 200 then it should return a value of 1 for fail. How can i do it the best way?.

e.g

----------------------------------------

#!/bin/bash

#cat test.sh
#function
function wgetTest {
wget -nv $1
awk ??
}

#call function and give the variable to work with
>wgetTest Google # expected return value from the function = 0
<0
>wgetTest http://blf909df.difjoij # expected return value from the function = 1
<1
----------------------------------------

Thanks in advance.

#2
mnmtanish

mnmtanish

    Newbie

  • Members
  • PipPip
  • 23 posts
I think you can get this one modified a bit to do what you want.
Simple bash script to monitor your webserver remotely on different ports | Share your knowledge!