If you need to sign into a site and download a file automatically with wget, here is a shell script for that:
COOKIE_FILE=cookie.txt
LOGIN_URL=”http://example.com/login?username=xxxx&password=xxxx”
login() {
echo “Signing in….”
wget –save-cookie cookie.txt $LOGIN_URL
return
}
print_usage() {
echo “Usage: $0 [URL]”
return
}
if [ $# -eq 0 ] ; then
print_usage
exit 1
fi
if [ ! -r $COOKIE_FILE ] ; then
login
fi
wget –load-cookie cookie.txt “$1” -O output.file
Leave a Reply