2

Currently, I'm checking a site with curl and grep for a particular pattern.

for i in {1..300}; do
  curl -s http://example.com | grep "Welcome to " 
  status=$? 
  # if status is 0 - print found else not found
  sleep 1;
done

How to convert this shell code into JavaScript code? I would like to print something like this:

//cURL req & get status of grep
if ( status == 0 )
  alert("Its found");
else
  alert("Not found Yet");

Thanks for any help or JSFiddle references. :)


EDIT: I came across this http://jsfiddle.net/GSSCD/203/ and this get sourcecode after javascript execution with curl I'm hoping for something like that based on JavaScript.

EDIT 2: Running on browser, need to verify this from browser. Platform already uses jQuery (Flask-based server).

5
  • 3
    Use AJAX. But browsers normally can't perform AJAX to other domains. Commented Jan 2, 2015 at 8:56
  • 2
    You can allow Access-Control-Allow-Origin: yourdomain-you-are-connecting-from.com to perform AJAX to other domains. Commented Jan 2, 2015 at 8:59
  • 1
    You need to include more details if you are running on a browser or node.js Commented Jan 2, 2015 at 9:08
  • thanks for the responses. pls see my new edit. Commented Jan 2, 2015 at 9:17
  • 2
    What platform? Browser? -- Not many options for the browser without using a proxy (send ajax request to server, server curl's target server, sends resposne back to browser) Commented Jan 2, 2015 at 9:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.