Skip to content

Instantly share code, notes, and snippets.

@kobapan
Last active October 11, 2017 08:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobapan/59817e15f2155ab38f2794b1e0ecbf57 to your computer and use it in GitHub Desktop.
Save kobapan/59817e15f2155ab38f2794b1e0ecbf57 to your computer and use it in GitHub Desktop.
【sh】RSS を配信していないホームページで、指定したhtmlに更新(変化)があった場合に、メールでお知らせする
#! /bin/sh
# RSS を配信していないホームページで、指定したhtmlに更新(変化)があった場合に、メールでお知らせする
# cron で利用する
url=http://hogehoge.ne.jp
title="「ほげほげ」で更新がありました"
to=to@example.com
from=from@example.com
cd $(dirname $0)
#前回のHTMLをリネーム
mv new.html old.html
#最新のHTMLを取得
wget -q $url -O new.html
#比較
diff --strip-trailing-cr -EbwBy --suppress-common-lines new.html old.html > diff.txt
#文字コードを取得
encode=`nkf -g diff.txt | tr -d '\r\n'`
#前回と違う場合のみメール送信
if [ -s diff.txt ]; then
(
echo "From: $from"
echo "To: $to"
echo "Subject: `echo $title | nkf --mime --ic=UTF-8 --oc=UTF-8`"
echo "Content-Type: text/plain; charset=UTF-8"
echo "Content-Transfer-Encoding: 8bit"
echo "MIME-Version: 1.0"
echo
cat diff.txt | nkf --ic=$encode --oc=UTF-8
) |sendmail -i -f $from $to
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment