Skip to content

Instantly share code, notes, and snippets.

@ysaotome
Last active August 14, 2017 20:22
Show Gist options
  • Save ysaotome/d14710539ad6a576f3dc to your computer and use it in GitHub Desktop.
Save ysaotome/d14710539ad6a576f3dc to your computer and use it in GitHub Desktop.
バッチ処理でURL一覧ファイルから順次Chroniumでのレンダリング結果をキャプチャして保存していくスクリプト(サムネイル作成機能付き)
#!/bin/bash
LOGS_DIR='/var/www/html/logs'
THUMBNAIL_BIG_DIR='/var/www/html/thumbnail_big'
THUMBNAIL_SMALL_DIR='/var/www/html/thumbnail_small'
SCREEN_NUM=${2}
for i in `awk '{print $1}' < $1`
do
arr=(`echo $i | tr -s ',' ' '`)
URL=${arr[0]}
NAME=${arr[1]}
DATE=`date +%Y%m%d%H%M`
echo "URL:${URL} OUTPUT:${THUMBNAIL_BIG_DIR}/${DATE}_${URL}_${NAME}.jpg"
$( /usr/bin/timeout 60 /usr/bin/xvfb-run --server-args="-screen ${SCREEN_NUM}, 1024x768x24" /usr/bin/CutyCapt --url=${URL} --delay=2000 --out=${THUMBNAIL_BIG_DIR}/${DATE}_${URL}_${NAME}.jpg)
$( cp -pr ${THUMBNAIL_BIG_DIR}/${DATE}_${URL}_${NAME}.jpg ${THUMBNAIL_SMALL_DIR}/${DATE}_${URL}_${NAME}.jpg )
$( /usr/bin/mogrify -resize 40% -quality 80 -verbose ${THUMBNAIL_SMALL_DIR}/${DATE}_${URL}_${NAME}.jpg )
done | tee -a ${LOGS_DIR}/capt_`date +%Y%m%d%H%M`.log
使い方
./capture.sh <URLリストファイル> <画面番号>
使い方例
シングルスレッド
./capture.sh urlA.list 0
マルチスレッド
./capture.sh urlA.list 0 &
./capture.sh urlB.list 1 &
実行に必要なパケージ(CentOS 6.5 x86_64)
yum --enablerepo=rpmforge,epel,remi install CutyCapt xorg-x11-server-Xvfb.x86_64 ImageMagick-last.x86_64
http://www.google.com,Google
http://www.nifty.com,@nifty
http://www.yahoo.co.jp,Yahoo!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment