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).

Badacadabra
  • 8,043
  • 7
  • 28
  • 49
webminal.org
  • 44,948
  • 37
  • 94
  • 125
  • 3
    Use AJAX. But browsers normally can't perform AJAX to other domains. – Barmar Jan 02 '15 at 08:56
  • 2
    You can allow Access-Control-Allow-Origin: http://yourdomain-you-are-connecting-from.com/ to perform AJAX to other domains. – Luba Jan 02 '15 at 08:59
  • 1
    You need to include more details if you are running on a browser or node.js – maskie Jan 02 '15 at 09:08
  • thanks for the responses. pls see my new edit. – webminal.org Jan 02 '15 at 09: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) – Ryan Jan 02 '15 at 09:24

0 Answers0