end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

wget --spider --mirror と grep --perl-regexp --only-matching でサイトにあるurlの一覧作成

↓こんな感じかと思います

#!/bin/bash

# domain と path を「,」で記載
declare -a sites_and_paths=(
    "ないしょ,/"
    "ないしょ,/"
    "ないしょ,/"
)

for site_and_paths_str in ${sites_and_paths[@]} ; do
    # 「,」を置換することで、split()します
    site_and_paths=(${site_and_paths_str//,/ })

    # domain名とpathの取り出し
    site=${site_and_paths[0]}
    unset site_and_paths[0]
    paths=${site_and_paths[@]}

    echo -n "" > url_list_tmp
    
    for path in  ${paths[@]} ; do
        echo "${site} ${path}"
        wget --spider --mirror --accept-regex=htm \
             --domains=${site} http://${site}${path} 2>&1 | \
            grep --perl-regexp "\-\-\d\d\d\d\-\d\d\-\d\d \d\d:\d\d:\d\d\-\-" \
                 >> url_list_tmp
    done
    
    grep --perl-regexp --only-matching "http.+" url_list_tmp | sort | uniq \
        > url_list_${site}

    sleep 2
done