Use Curl to Monitor Websites: Difference between revisions

From EggeWiki
m (New page: Here's a simple script which you can check to see if a website is up and responding. <geshi lang="bash"> #!/bin/bash # $1 = URL to check # $2 = expected text to be found in the page func...)
 
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 8: Line 8:
function c() {
function c() {
   echo -en "Site $1\t"
   echo -en "Site $1\t"
   curl --silent --show-error --proxy-user ${USER}:${HTTP_PROXY_PASS} --proxy proxy3.macbank:8080 --location \
   curl --silent --show-error --proxy-user ${USER}:${HTTP_PROXY_PASS} --proxy ${HTTP_PROXY} --location \
   --dump-header /tmp/$$.header "$1" -o/tmp/$$ && grep -q "$2" /tmp/$$
   --dump-header /tmp/$$.header "$1" -o/tmp/$$ && grep -q "$2" /tmp/$$
   if [ $? -eq 0 ]; then
   if [ $? -eq 0 ]; then
Line 22: Line 22:
c "http://www.google.com.au/" 'Microsoft'
c "http://www.google.com.au/" 'Microsoft'
</geshi>
</geshi>
[[Category:Bash]]

Latest revision as of 23:01, 16 July 2009

Here's a simple script which you can check to see if a website is up and responding.

<geshi lang="bash">

  1. !/bin/bash
  1. $1 = URL to check
  2. $2 = expected text to be found in the page

function c() {

 echo -en "Site $1\t"
 curl --silent --show-error --proxy-user ${USER}:${HTTP_PROXY_PASS} --proxy ${HTTP_PROXY} --location \
  --dump-header /tmp/$$.header "$1" -o/tmp/$$ && grep -q "$2" /tmp/$$
 if [ $? -eq 0 ]; then
   echo "pass"
 else
   echo "failed to match '$2'"
   cat /tmp/$$.header
 fi
 /bin/rm /tmp/$$ /tmp/$$.header

}

c "http://www.theeggeadventure.com/" 'Brian' c "http://www.google.com.au/" 'Microsoft' </geshi>