Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simple script to check if a webpage has been updated

Tags:

bash

web

scrape

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.

like image 975
Programmer Avatar asked Jan 31 '12 17:01

Programmer


People also ask

How do I find the script of a website?

To view only the source code, press Ctrl + U on your computer's keyboard. Right-click a blank part of the web page and select View source from the pop-up menu that appears.


1 Answers

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.

like image 186
Chris Seymour Avatar answered Oct 12 '22 10:10

Chris Seymour