cURL / Mailing Lists / curl-users / Single Mail

curl-users

Problem with login using curl in a shell script

From: [cristo] <ccristoo_at_gmail.com>
Date: Thu, 4 Jun 2009 14:50:26 -0500

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

-------------------------------------------------------------------
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