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