Last active
October 11, 2017 08:28
-
-
Save kobapan/59817e15f2155ab38f2794b1e0ecbf57 to your computer and use it in GitHub Desktop.
【sh】RSS を配信していないホームページで、指定したhtmlに更新(変化)があった場合に、メールでお知らせする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# RSS を配信していないホームページで、指定したhtmlに更新(変化)があった場合に、メールでお知らせする | |
# cron で利用する | |
url=http://hogehoge.ne.jp | |
title="「ほげほげ」で更新がありました" | |
[email protected] | |
[email protected] | |
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