cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Problem with login using curl in a shell script

From: Jochen Roderburg <Roderburg_at_uni-koeln.de>
Date: Thu, 04 Jun 2009 22:19:37 +0200

Zitat von "[cristo]" <ccristoo_at_gmail.com>:

> Hello,
>
> I'm writing a shell script that logs in a website and downloads its home
> page. I am already able to login using curl in a terminal via the following
> commands:
>
>
> 1. curl --cookie-jar cjar --output /dev/null http://www.gamers.vg
> 2. curl -v --cookie cjar --cookie-jar cjar --data 'remember=OF' --data
> 'tag=nickname' --data 'password=password' --location --output
> ./temp/temp.html http://www.gamers.vg/sec/login/
>
> I'm using the first command to set up the cookies used by the site, and the
> second one to access the web site and downloading the main page in
> ./temp/temp.html file.
>
> I'm having problems to access the web site when using those commands in the
> following shell script:
>
> #!/bin/bash
>
> # local variables
> ############################
>
> tag=nickname
> password=password
>
> # initial cookie
> ############################
>
> echo initial cookie ...
>
> curl -v --cookie-jar cjar --output /dev/null http://www.gamers.vg
>
> echo login ...
>
> curl -v --cookie cjar --cookie-jar cjar \
> --data \'remember=OF\' \
> --data \'tag=$tag\' \
> --data \'password=$password\' \
> --location \
> --output ./temp/temp.html \
> http://www.gamers.vg/sec/login/
>
> echo done!
>
> The exit status of curl says everything is ok, but when I read temp.html I
> always have a site's error page saying that I am missing fields of the login
> form.
>
> I analized the http request made by firefox when I do a normal login and
> found that there are two hidden fields added to the request that have
> auto-generated values that change with every submit.
>
> I search in the page's source the code that adds those fields but couldn't
> find anything.
>
> Can somebody help me to find out why I can login when I call curl from a
> terminal but not when I call it in a shell script?
>
> Thanks in advance

Because you are obviously using a different curl command line in your
script. ;-)

Why are you quoting the quoting apostrophes there a second time?
So they are sent as part of the posted data and that is certainly not correct.

Best regards,

Jochen Roderburg
RRZK
University of Cologne
Robert-Koch-Str. 10 Tel.: +49-221/478-7024
D-50931 Koeln E-Mail: Roderburg_at_Uni-Koeln.DE
Germany

-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-06-04