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.
            Asked
            
        
        
            Active
            
        
            Viewed 2.9k times
        
    2 Answers
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
- 
                    Super helpful! Thanks for your time and effort! – Ahmed Mahmoud Aug 04 '20 at 11:43
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
- 
                    
- 
                    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
