12

There is some information that I am waiting for on a website. I do not wish to check it every hour. I want a script that will do this for me and notify me if this website has been updated with the keyword that I am looking for.

Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
Programmer
  • 421
  • 1
  • 7
  • 21

2 Answers2

15

Here is a basic bash script for checking if the webpage www.nba.com contains the keyword Basketball. The script will output www.nba.com updated! if the keyword is found, if the keyword isn't found the script waits 10 minutes and checks again.

#!/bin/bash

while [ 1 ];
do
    count=`curl -s "www.nba.com" | grep -c "Basketball"`

    if [ "$count" != "0" ]
    then
       echo "www.nba.com updated!"
       exit 0   
    fi
    sleep 600   
done

We don't want the site or the keyword hard-coded into the script, we can make these arguments with the following changes.

#!/bin/bash

while [ 1 ];
do
    count=`curl -s "$1" | grep -c "$2"`

    if [ "$count" != "0" ]
    then
       echo "$1 updated!"
       exit 0
    fi
    sleep 600
done

Now to run the script we would type ./testscript.sh www.nba.com Basketball. We could change the echo command to have the script send an email or any other preferred way of notification. Note we should check that arguments are valid.

Luc M
  • 16,630
  • 26
  • 74
  • 89
Chris Seymour
  • 83,387
  • 30
  • 160
  • 202
0

go and configure a google alert..

You can also crawl the website and search for the keyword you are interested in.

naresh
  • 2,113
  • 20
  • 32
  • Yes, but I want to search a specific page. – Programmer Jan 31 '12 at 18:00
  • write a script that periodically downloads the content from that page and checks if the word you are interested in exists.. You can make some optimizations like: don't check if page hasn't been updated since you last checked etc.. – naresh Jan 31 '12 at 18:02