{"id":65,"date":"2006-01-12T17:50:00","date_gmt":"2006-01-12T17:50:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=65"},"modified":"2006-01-12T17:50:00","modified_gmt":"2006-01-12T17:50:00","slug":"wget-login-cookie","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=65","title":{"rendered":"wget, login &amp; cookie"},"content":{"rendered":"<p>If you need to sign into a site and download a file automatically with wget, here is a shell script for that:<\/p>\n<p><textarea name=\"code\" class=\"php\"><br \/>\n#!\/bin\/sh<\/p>\n<p>COOKIE_FILE=cookie.txt<br \/>\nLOGIN_URL=&#8221;http:\/\/example.com\/login?username=xxxx&#038;password=xxxx&#8221;<\/p>\n<p>login() {<br \/>\n  echo &#8220;Signing in&#8230;.&#8221;<br \/>\n  wget &#8211;save-cookie cookie.txt $LOGIN_URL<br \/>\n  return<br \/>\n}<\/p>\n<p>print_usage() {<br \/>\n  echo &#8220;Usage: $0 [URL]&#8221;<br \/>\n  return<br \/>\n}<\/p>\n<p>if [ $# -eq 0 ] ; then<br \/>\n  print_usage<br \/>\n  exit 1<br \/>\nfi<\/p>\n<p>if [ ! -r $COOKIE_FILE ] ; then<br \/>\n  login<br \/>\nfi<\/p>\n<p>wget &#8211;load-cookie cookie.txt &#8220;$1&#8221; -O output.file<br \/>\n<\/textarea><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you need to sign into a site and download a file automatically with wget, here is a shell script for that: #!\/bin\/sh COOKIE_FILE=cookie.txt LOGIN_URL=&#8221;http:\/\/example.com\/login?username=xxxx&#038;password=xxxx&#8221; login() { echo &#8220;Signing in&#8230;.&#8221; wget &#8211;save-cookie cookie.txt $LOGIN_URL return } print_usage() { echo &#8220;Usage: $0 [URL]&#8221; return } if [ $# -eq 0 ] ; then print_usage exit 1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/65"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=65"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/65\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}