Skip to content

Instantly share code, notes, and snippets.

@libraplanet
Created March 10, 2019 22:05
Show Gist options
  • Save libraplanet/770ba4230f1c0138e2ac1c5723c9d0f5 to your computer and use it in GitHub Desktop.
Save libraplanet/770ba4230f1c0138e2ac1c5723c9d0f5 to your computer and use it in GitHub Desktop.
batch download shell scripts.
USAGE : dlc.sh [list file] [output dir]
curlを用いた一括バッチ ダウンロード スクリプト。
URLのパターンと保存先のリストから一括ダウンロード。
URLのパターン書式はcurlのヘルプを参照。
list file : ダウンロードを行うリスト ファイルを指定する。
リストは1行ごとに出力先とURLをタブ区切りで列挙する。
output dir : 出力先のフォルダをする。デフォルトは『./download/』
実際の保存先は
${output dir}/${list fileで指定されたフォルダ}/ダウンロード ファイル名
となる。
USAGE : dlw.sh [list file] [output dir]
wgetを用いた一括バッチ ダウンロード スクリプト。
URLのリストから一括ダウンロード。
list file : ダウンロードを行うURLのリスト ファイルを指定する。
output dir : 出力先のフォルダをする。デフォルトは『./download/』
実際の保存先は
${output dir}/ダウンロード ファイル名
となる。
#directory #URL
dir0 http://aaaa/[1-99].png
dir1 http://bbbb/[001-999].png
#!/bin/sh
base_dir=${PWD}
base_download_dir=./download/
echo "[init]"
list_fname=${1}
if [ "${2}" != "" ];then
base_download_dir=${2}
fi
echo base_dir=${base_dir}
echo list_fname=${list_fname}
echo base_download_dir=${base_download_dir}
echo ""
echo "[previw list]"
cat "${list_fname}" | while IFS= ; read line;
do
echo ${line}
done
echo ""
echo "[proc]"
max_line=`cat "${list_fname}" | wc -l`
cur_line=0
cat "${list_fname}" | while IFS= ; read line;
do
#init
cd "${base_dir}"
cur_line=$((cur_line + 1))
#proc
if [ "${line:0:1}" == "#" ] ; then
echo "line#[${cur_line}/${max_line}] skip line..."
else
dir=`echo ${line} | awk -F"[\t]" '{print $1}'`
url=`echo ${line} | awk -F"[\t]" '{print $2}'`
work_dir=${base_download_dir%/}/${dir}
echo "line#[${cur_line}/${max_line}] dir=${dir}, url=${url}"
mkdir -p "${work_dir}"
if ! cd "${work_dir}"; then
echo "faild change directory to '${work_dir}'"
else
curl -f -O "${url}"
fi
fi
done
#URL
http://xxxxx/image_001.jpg
http://xxxxx/image_002.jpg
http://xxxxx/image_003.jpg
http://xxxxx/image_101.jpg
http://xxxxx/image_102.jpg
http://xxxxx/image_103.jpg
http://xxxxx/image_202.jpg
http://xxxxx/image_202.jpg
http://xxxxx/image_202.jpg
#!/bin/sh
out_dir=./download/
echo "[init]"
list_fname=${1}
if [ "${2}" != "" ];then
out_dir=${2}
fi
echo list_fname=${list_fname}
echo out_dir=${out_dir}
echo ""
echo "[proc]"
max_line=`cat "${list_fname}" | wc -l`
cur_line=0
cat "${list_fname}" | while IFS= ; read line;
do
#init
cur_line=$((cur_line + 1))
#proc
if [ "${line:0:1}" == "#" ] ; then
echo "line#[${cur_line}/${max_line}] skip line..."
else
echo "line#[${cur_line}/${max_line}] ${line}"
wget -N -P "${out_dir%/}/" ${line}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment