Advertisement
Kimarite

Monitoring a web page for changes using bash

Feb 10th, 2019
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # monitor.sh - Monitors a web page for changes
  4. # sends an email notification if the file change
  5. # source: http://bhfsteve.blogspot.com/2013/03/monitoring-web-page-for-changes-using.html
  6.  
  7. USERNAME="[email protected]"
  8. PASSWORD="itzasecret"
  9. URL="http://thepage.com/that/I/want/to/monitor"
  10.  
  11. for (( ; ; )); do
  12. mv new.html old.html 2> /dev/null
  13. curl $URL -L --compressed -s > new.html
  14. DIFF_OUTPUT="$(diff new.html old.html)"
  15. if [ "0" != "${#DIFF_OUTPUT}" ]; then
  16. sendEmail -f $USERNAME -s smtp.gmail.com:587 \
  17. -xu $USERNAME -xp $PASSWORD -t $USERNAME \
  18. -o tls=yes -u "Web page changed" \
  19. -m "Visit it at $URL"
  20. sleep 10
  21. fi
  22. done
  23.  
  24. -----
  25.  
  26. Magyarázat / Know How
  27.  
  28. Then from a bash prompt I run it with the following command:
  29.  
  30. nohup ./monitor.sh &
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement