Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #######################################################
- #######################################################
- ### usage: webch [-ciqr] url
- ### usage: webch [-i INTERVAL] [-r REPEAT] [-q] [-c "COMMAND(S) TO EXECUTE"] url
- ### options:
- ### -i, --interval : time (in seconds) to wait between downloads/page checks (default=30)
- ### -r, --repeat : how many times to repeat (ie. how many changes till exit) (default=1)
- ### -q, --quiet : turns off beep after each change
- ### -c, --command : command(s) to execute after each change (default=echo "It changed!")
- #####################################################
- #
- #
- function webch(){
- inter=30
- repeat=1
- beep=true
- com='echo "It changed!"'
- OPTS=`getopt -o qi:r:-c: -l quiet,interval:,repeat:,command: -- "$@"`
- if [ $? -ne 0 ];
- then
- return 1
- fi
- eval set -- "$OPTS"
- while true ; do
- case "$1" in
- -q|--quiet) beep=false; shift;;
- -i|--interval) inter=$2 ; shift 2;;
- -r|--repeat) repeat=$2; shift 2;;
- -c|--command) com=$2; shift 2;;
- --) shift; break;;
- *) break;;
- esac
- done
- url=$1 #Passing the first leftover argument to the variable url
- f1=/tmp/.`mcookie`
- f2=/tmp/.`mcookie`
- wget -q -O $f1 $url
- while [ $repeat -ne 0 ]; do
- tmp=0 #Setting tmp to 0
- while [ $tmp -eq 0 ] ; do
- sleep $inter #Waiting before fetching the page
- wget -q -O $f2 $url #Fetching page
- cmp -s $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
- echo whileloop
- done
- rm $f1
- f1=$f2
- f2=/tmp/.`mcookie`
- if [ $tmp -gt 1 ] #Checks if cmp gave an error
- then
- echo "An error occured"
- return $tmp
- fi
- if $beep;
- then
- echo -en "\007"
- fi
- eval $com
- let repeat=repeat-1
- done
- rm $f1 #removing files that are nolonger needed
- return 0
- }
- ###########################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement