Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function webch(){
- f1=/tmp/.`mcookie` #File to save webpage in the first time
- f2=/tmp/.`mcookie` #File to save webpage in to compare to first download
- url=$1 #Passing the first argument to the variable url
- wget -q -O $f1 $url #Fetching the page for the first time
- tmp=0 #Setting tmp to 1
- if [ -z $2 ]; #Checking if time to wait has been supplied (in seconds)
- then
- time=30 #Default if not supplied
- else
- time=$2 #Setting time to what was passed
- fi
- while [ $tmp -eq 0 ] ; do
- sleep $time #Waiting before fetching the page
- wget -q -O $f2 $url #Fetching page
- cmp $f1 $f2 #Checking first fetch vs last. cmp exits with 0 if files are the same, 1 if they are different
- tmp=$? #Setting what cmp exited with to tmp
- done
- rm $f1 $f2 #removing files that are nolonger needed
- if [ $tmp -gt 1 ] #Checks if cmp gave an error
- then
- echo "An error occured"
- exit 127
- fi
- if [ -z $3 ]; #Checks if an action has been supplied
- then
- echo "It changed!" #Default output if no action has been supplied
- echo -en "\007" #Beeps once to notify that a change has occured
- else
- ${@:3} #Completes supplied command(s)
- fi
- return 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement