Skip to content

Instantly share code, notes, and snippets.

@daipresents
Last active December 18, 2015 10:58
Show Gist options
  • Save daipresents/5771783 to your computer and use it in GitHub Desktop.
Save daipresents/5771783 to your computer and use it in GitHub Desktop.
とあるBASIC認証がかかってるWevDAVサイトのPDFリンクを全部ダウンロードするシェル。 hrefがファイル名になっていた場合のサンプルなので、ダウンロードしたいファイルのURLの場合によっては修正が必要。
#!/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