Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-25-2009, 01:30 PM   #1
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:

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
2) download-funktions
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 ]
		# Download OK
		echo -e "$TIMENOW: Download Update OK" >> $LOGFILE
		echo -e "Download Update OK"

		echo -e "Download Update Failed"
3) the Main-File

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

echo $MYID
echo $SERVER

after executing, there is following output
/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:
>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!

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

Rep: Reputation: 1971Reputation: 1971Reputation: 1971Reputation: 1971Reputation: 1971Reputation: 1971Reputation: 1971Reputation: 1971Reputation: 1971Reputation: 1971Reputation: 1971
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
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!

* About to connect() to port 80 (#0)
*   Trying connected
* Connected to ( port 80 (#0)
> User-Agent: curl/7.19.0 (arm-unknown-linux-gnu) libcurl/7.19.0 OpenSSL/0.9.8g zlib/1.2.3
> Host:
> 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
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...


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 11:00 PM.

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