lundi 30 août 2021

Improve my cron script for website change notification

I've been using a script through cron to check if a web page has changed.

Everything is running smoothly but this is my first attempt and I know it could be better. I'm a noob so take it easy.

I've hobbled this together through many sources. The standard services that check if a webpage has changed didn't work on my webpage of instance because each instance created a new shopping cart ID. Instead, I looked for alike with say article:modified_time that was my TextofInterest and it will grab that whole line and compare it to the same line in the prior file.

Things to maybe do better:

  1. I'd like to define each file (.txt, .html, websites) at the beginning.

  2. I've also run into some other code where it looks like it might not have to save to a file and run in memory?

  3. Currently saving to a flash drive (open media vault), I'd like to change the directory to a different drive for the writes of the files.

Any other improvements are welcome.

Here is working code:

#!/bin/bash
cp Current.html Prior.html
wget -O Current.html 'https://websiteofinterest.com/
awk '{if(match($0,"TextofInterest")){s=1} else s=0}s' Prior.html > Prior.txt
awk '{if(match($0,"TextofInterest")){s=1} else s=0}s' Current.html > Current.txt
diff -q Current.txt Prior.txt || diff Current.txt Prior.txt | mail -s "Website Canged" "Emailtosendto@email.com"



Aucun commentaire:

Enregistrer un commentaire