Glam Prestige Journal

Bright entertainment trends with youth appeal.

I want to write a script to check out if the website is working fine by checking out some of it is contents. If the content exists in the result, it prints a message telling the website is working fine, otherwise, it will show an error:

#!/bin/bash
webserv="10.1.1.1"
Keyword="helloworld" # enter the keyword for test content
if (curl -s "$webserv" | grep "$keyword") # if the keyword is in the conent echo " the website is working fine"
else echo "Error"

Any suggestion how to do that?

2 Answers

You're mostly there. Just fix your syntax:

if curl -s "$webserv" | grep "$keyword"
then # if the keyword is in the conent echo " the website is working fine"
else echo "Error"
fi

Note the then and fi.

1

A tiny amend: when setting the variable and using it later, the case needs to match in the two places (ie 'keyword', not 'Keyword'). The full code that works for me:-

#!/bin/bash
webserv="10.1.1.1"
keyword="helloworld" # enter the keyword for test content
if curl -s "$webserv" | grep "$keyword"
then # if the keyword is in the content echo " the website is working fine"
else echo "Error"
fi

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy