Last active
December 18, 2015 10:58
-
-
Save daipresents/5771783 to your computer and use it in GitHub Desktop.
とあるBASIC認証がかかってるWevDAVサイトのPDFリンクを全部ダウンロードするシェル。
hrefがファイル名になっていた場合のサンプルなので、ダウンロードしたいファイルのURLの場合によっては修正が必要。
This file contains 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/bash | |
export debug=false | |
export extension=pdf | |
export username=${Set a username} | |
export password=${Set a password} | |
export url=${PDF page url} | |
export output=/Users/yourname/Downloads | |
export number=3 | |
curl -o index.html --user ${username}:${password} ${url}/ | |
for file in `cat index.html | grep ${extension} | tail -${number} | sed -e "s/.*<a href=\"//" -e "s/${extension}.*/${extension}/"`; do | |
if [ ${debug} = "true" ]; then | |
echo "Debug mode: ${file}" | |
else | |
echo "Download ${file}" | |
curl -o ${output}/${file} --user ${username}:${password} ${url}/${file} | |
fi | |
done | |
rm -f index.html | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment