Skip to content

Instantly share code, notes, and snippets.

@mohan-mu
Forked from djromero/monitor-page.sh
Created August 1, 2017 11:34
Show Gist options
  • Select an option

  • Save mohan-mu/8639c8a1cc14010738b2d5354caa7e0f to your computer and use it in GitHub Desktop.

Select an option

Save mohan-mu/8639c8a1cc14010738b2d5354caa7e0f to your computer and use it in GitHub Desktop.

Revisions

  1. @djromero djromero revised this gist Apr 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion monitor-page.sh
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ URL="http://example.com/monitored/page.html"
    TO="email@example.com another@example.com"
    HANDLER="@user @friend"

    USERNAME="sender@example.com"
    USERNAME="sender@gmail.com"
    PASSWORD="secret!"


  2. @djromero djromero revised this gist Apr 13, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions monitor-page.sh
    Original file line number Diff line number Diff line change
    @@ -11,11 +11,13 @@
    # sudo apt-get install libio-socket-ssl-perl libcrypt-ssleay-perl libnet-ssleay-perl
    # sudo apt-get sendemail

    URL="http://example.com/monitored/page.html"
    TO="email@example.com another@example.com"
    HANDLER="@user"
    HANDLER="@user @friend"

    USERNAME="sender@example.com"
    PASSWORD="secret!"
    URL="http://example.com/monitored/page.html"


    while true ; do
    if [ -f new.html ] ; then
  3. @djromero djromero revised this gist Apr 13, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion monitor-page.sh
    Original file line number Diff line number Diff line change
    @@ -32,7 +32,7 @@ while true ; do
    -f $USERNAME \
    -s smtp.gmail.com:587 -xu $USERNAME -xp $PASSWORD \
    -o tls=yes \
    -u "Entradas Rivas page changed" \
    -u "The page changed" \
    -m "Visit it at $URL\n\n${DIFF_OUTPUT}"
    fi
    sleep 300
  4. @djromero djromero created this gist Apr 13, 2015.
    39 changes: 39 additions & 0 deletions monitor-page.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/bin/bash
    # inspired in "Monitoring a web page for changes using bash"
    # http://bhfsteve.blogspot.com.es/2013/03/monitoring-web-page-for-changes-using.html
    # monitor.sh - Monitors a web page for changes
    # sends an email notification and a tweet if the file changes

    # requirements:
    # - twitter from the command line [https://github.com/sferik/t]
    # gem install t
    # - sendemail
    # sudo apt-get install libio-socket-ssl-perl libcrypt-ssleay-perl libnet-ssleay-perl
    # sudo apt-get sendemail

    TO="email@example.com another@example.com"
    HANDLER="@user"
    USERNAME="sender@example.com"
    PASSWORD="secret!"
    URL="http://example.com/monitored/page.html"

    while true ; do
    if [ -f new.html ] ; then
    mv new.html old.html 2> /dev/null
    fi
    curl -s $URL -L --compressed > new.html
    # for better results add a grep to exclude lines that always change (like a date, etc.)
    # | egrep -v 'this|that'
    DIFF_OUTPUT=`diff --suppress-common-lines -y new.html old.html`
    if [ "x" != "x${DIFF_OUTPUT}" ] ; then
    t update "${HANDLER} hey, the webpage $URL just changed"
    sendEmail \
    -t $TO \
    -f $USERNAME \
    -s smtp.gmail.com:587 -xu $USERNAME -xp $PASSWORD \
    -o tls=yes \
    -u "Entradas Rivas page changed" \
    -m "Visit it at $URL\n\n${DIFF_OUTPUT}"
    fi
    sleep 300
    done