Logging in with cURL

Sometimes you might want to monitor or grab pages directly from scripts. It is easy, unless your DokuWiki installation requires logging in. In that case you can use cookie and POST variable support in curl.

Step 1 - log in and store cookie.

curl -d "u=<username>&p=<password>" --cookie-jar cjar http://www.my.wiki/path/?do=login

This stores login cookie in a file named cjar in the current directory. Now we can retrieve pages that require us to be logged in.

Step 2 - retrieve pages.

Now we can easily retrieve protected pages, but we still have to indicate to DokuWiki that we are the same person who logged in previously.

curl --cookie cjar --cookie-jar cjar http://www.my.wiki/path/that/requires/login

This reuses cookie from the cjar file and allows us to retrieve those pages.

See also

curl.haxx.se