Skip to content

Instantly share code, notes, and snippets.

@komasaru
Created October 20, 2014 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/60697d7115b20c1d8c2d to your computer and use it in GitHub Desktop.
Save komasaru/60697d7115b20c1d8c2d to your computer and use it in GitHub Desktop.
Bash script to check a difference between a saved-html and a current-html.
#!/bin/bash
# 定数定義
URL="http://www.foo.xxx/bar/baz/" # チェックした Web サイトの URL
FILE_S="/path/to/saved.html" # 前回取得 HTML のファイル
FILE_C="/path/to/current.html" # 今回取得 HTML のファイル
# 当スクリプトの存在ディレクトリへ移動
cd /path/to/
# 前回取得 HTML ファイルが存在しなければ、新たに取得して終了
if [ ! -e $FILE_S ]; then
curl -o $FILE_S $URL > /dev/null
exit
fi
# 新規に HTML を取得
curl -o $FILE_C $URL > /dev/null
# 前回取得 HTML と今回取得 HTML を比較
diff $FILE_S $FILE_C
# ファイルに差異があれば、
# 今回取得ファイルをタイムスタンプ付きで保存
# さらに、今回取得ファイルを前回取得ファイルとして保存
if [ $? -ne 0 ]; then
dt=`date '+%y%m%d_%H%M%S'`
cp $FILE_C data/${dt}.html
cp $FILE_C $FILE_S
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment