LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-25-2009, 01:30 PM   #1
holly123
LQ Newbie
 
Registered: Oct 2009
Posts: 9

Rep: Reputation: 0
Question big problem with curl and bash


hi guys,

i'm here with my first question because i have big problems with downloading a file via curl + bash...

downloading files via curl is easy, if i hard-code the command and press enter in the terminal. but when i put it in a script, something goes wrong and there are some errors like:
"Cannot resolve host" or "http 404 - errors"


i have to download the file like this:
Code:
http://xxx.xxx.xxx.xxx/aspx/download.aspx?ID=xxxxxxx.xxxxx.xxx&TYPE=DOWM

i have 3 files:
1) a config-file
with the server-url/ip, savepath, etc.
2) a file with all functions
download-function which uses curl for downloading
3) a main-bash-script


the contents are:

1) config-file
Code:
MYID=d9281511-6fd4-43de-851a-7e97f915da8f
SERVER=http://xxx.xxx.xxx.xxx
MAX_DOWNLOADTIME=20
MAX_UPLOADTIME=60
LOGFILE=/tmp/download.log
SAVEPATH=/mnt/disk
2) download-funktions
Code:
dwnTimetable() {

curl http://$SERVER/aspx/download.aspx -G -d "TYPE=DOWN" -d "ID=$MYID" -m $MAX_DOWNLOADTIME -w '\nHTTP STATUS: %{http_code}' -o $SAVEPATH/timetable.txt | grep "HTTP STATUS: 200" || rm $SAVEPATH/timetable.txt

	if [ -s $SAVEPATH/timetable.txt ]
	then
		# Download OK
		echo -e "$TIMENOW: Download Update OK" >> $LOGFILE
		echo -e "Download Update OK"

	else
		echo -e "Download Update Failed"
		exit
	fi
}
3) the Main-File
Code:
#!/bin/ash

. ./config.cfg				# Load Configuration-File
. ./functions.res 			# Load General Functions
. ./download_functions.res 	        # Load Download Functions


echo $MYID
echo $SERVER
echo $SAVEPATH

dwnTimetable
after executing, there is following output
Code:
xxx.xxx.xxx.xxx
/mnt/disk
/timetable.txtd to create the file /mnt/disk
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   311  100   311    0     0   1862      0 --:--:-- --:--:-- --:--:--  1862
curl: (23) Failed writing body (0 != 311)
Download Update Failed
[root@wrap tmp]$
and the server tells:
Code:
>HTTP Error 400. The request is badly formed.
its crazy, because when i write the curl-command in the terminal and execute it, the file will be downloaded without any problems!


hope somebody can help me!

best,
holly123
 
Old 10-25-2009, 01:40 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966Reputation: 1966
well add a few -v's to both command lines and compare and contrast the HTTP request that is sent. If the first url works though, why are you using a completely different format in the script? If that's what you mean about the errors early on in your question, I imagine you're not escaping characters correctly or something
 
Old 10-25-2009, 01:58 PM   #3
holly123
LQ Newbie
 
Registered: Oct 2009
Posts: 9

Original Poster
Rep: Reputation: 0
adding -v's print the header and there is an error in line 4 (the url-string is damaged)...

it should be HTTP/1.1 aspx/download.aspx?TYPE=DOWN&ID=.....

i cannot explain this error! maybe someone can!


Code:
* About to connect() to 194.xxx.xxx.xxx port 80 (#0)
*   Trying 194.xxx.xxx.xxx... connected
* Connected to 194.xxx.xxx.xxx (194.xxx.xxx.xxx) port 80 (#0)
 HTTP/1.1px/download.aspx?TYPE=DOWN&ID=d9281511-6fd4-43de-851a-7e97f915da8f
> User-Agent: curl/7.19.0 (arm-unknown-linux-gnu) libcurl/7.19.0 OpenSSL/0.9.8g zlib/1.2.3
> Host: 194.xxx.xxx.xxx
> Accept: */*
> 
< HTTP/1.1 400 Bad Request
< Content-Type: text/html; charset=us-ascii
< Server: Microsoft-HTTPAPI/2.0
< Date: Sun, 25 Oct 2009 18:53:57 GMT
< Connection: close
< Content-Length: 311
< 
{ [data not shown]
 
Old 10-25-2009, 02:52 PM   #4
holly123
LQ Newbie
 
Registered: Oct 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Problem Solved!

Thank you for your help. But my Problem was that i saved my config-File in a Windows-Format with wrong Line-Breaks...

I changed to Unix/Linux-LineBreak-Format and its working fine...

Damn, this mistake costs me abouts 3 hours...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH variables, quotation marks and cURL struggles matthias_k Programming 13 01-27-2013 04:56 PM
[acer Extensa 5620Z] I got a big big problem, please help ^^ VodkaRocks Linux - Wireless Networking 11 06-26-2009 07:08 AM
Bash variable problem: cURL -b parameter (string form e.g. "name=value;n2=v2") sithemac Other *NIX 3 07-09-2008 06:15 PM
BIG BIG PROBLEM with nvidia driver for linux x86 basshead62887 Linux - Hardware 5 09-12-2007 12:33 AM
Installing RH 9 with RAID 5 --Big, big Problem!!! rhonneil Linux - Software 2 09-25-2003 08:13 PM


All times are GMT -5. The time now is 03:06 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration