Curl , download file with user:pass in bash script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Curl , download file with user:pass in bash script
# 1  
Old 01-04-2019
Curl , download file with user:pass in bash script

Hello,
My question is about curl command. (ubuntu14.04)
In terminal, I am able to download my mainfile with:

Code:
curl -u user1:pass1 http://11.22.33.44/*******

When I convert it into bash script like this:

Code:
#!/bin/bash
cd /root/scripts
computer_ip=11.22.33.44
curl -u $1:$2 http://$computer_ip/****** > mainfile
#curl -u $1:$2 -O mainfile http://$computer_ip/****** #this is also not working

gives nothing. I tried different ways like these:

Code:
curl -u '$1':'$2' http://$computer_ip/****** > mainfile

Code:
curl -u "$1":"$2" http://$computer_ip/****** > mainfile

Code:
curl -u ""$1":"$2"" http://$computer_ip/****** > mainfile

I run the script like:
Code:
./script.sh user1 pass1

Could you please tell me what I am missing?
Thanks in advance
Boris

Last edited by baris35; 01-04-2019 at 10:33 AM..
# 2  
Old 01-04-2019
Having you tried running the script with the set -x? What does that come back with?
What happens if you remove > mainfile ? What do you get?
Have you tried running curl in verbose (-v) mode?
# 3  
Old 01-04-2019
Hello Vgersh99,
I do not know how to run with set -x
If I remove > mainfile how may I redirect the output to a file so that I would be able to manage some other tasks at following steps of the script, which were not mentioned in my post ?
curl -v -u $1:$2 ****** is not giving an output.

Kind regards
Boris
# 4  
Old 01-04-2019
Code:
#!/bin/bash
set -x 
cd /root/scripts
computer_ip=11.22.33.44
curl -u $1:$2 http://$computer_ip/******
#curl -u $1:$2 -O mainfile http://$computer_ip/****** #this is also not working

Remove > mainfile for debugging purposes - once debugged, you can put it back in.
# 5  
Old 01-04-2019
Thank You Vgersh99,
Here you are:
Code:
+ cd /root/scripts
+ computer_ip=****************
+ curl -u : 'http://*******************'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Unauthorized</TITLE>
</HEAD><BODY>

I run it like ./script.sh user1 pass1

Last edited by baris35; 01-04-2019 at 12:59 PM..
# 6  
Old 01-04-2019
Quote:
Originally Posted by baris35
Thank You Vgersh99,
Here you are:
Code:
+ cd /root/scripts
+ computer_ip=****************
+ curl -u : 'http://*******************'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>401 Unauthorized</TITLE>
</HEAD><BODY>

I run it like ./script.sh user1:pass1
Well... 401 Unauthorized should be a good starting point.
If the script is as I posted with set -x, you should run it as ./script.sh user1 pass1
# 7  
Old 01-04-2019
My typo error, yes I do run it like you posted..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Pass config file to bash script

I just want to make sure I am understanding how to pass a config file to a bash script . In the below I pass to arguments to a script, then define them in the script as id and config. I then source config using ., if I understand correctly the variables in the config file can now be used by the... (11 Replies)
Discussion started by: cmccabe
11 Replies

2. Shell Programming and Scripting

Curl to download file from subdivx.com after following location without knowing the file name/extens

This question could be specific to the site subdivx.com In the past, I've been able to download a file following location using cURL but there is something about subdivx.com that's different and can't figure out how to get it to work. I tried the following directly in the terminal with no... (5 Replies)
Discussion started by: MoonD
5 Replies

3. Shell Programming and Scripting

Curl parallel download file list

Hello guys, first post sorry if I did some mess here =) Using Ubuntu 14.04lts 64bits server version. I have a list (url.list) with only URLs to download, one per line, that looks like this: http://domain.com/teste.php?a=2&b=3&name=1 http://domain.com/teste.php?a=2&b=3&name=2 ...... (6 Replies)
Discussion started by: tonispa
6 Replies

4. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

5. Shell Programming and Scripting

Curl command to download multiple files with a file prefix

I am using the below curl command to download a single file from client server and it is working as expected curl --ftp-ssl -k -u ${USER}:${PASSWD} ftp://${HOST}:${PORT}/path/to/${FILE} --output ${DEST}/${FILE} let say the client has 3 files hellofile.101, hellofile.102, hellofile.103 and I... (3 Replies)
Discussion started by: r@v!7*7@
3 Replies

6. Shell Programming and Scripting

Curl download zip extract large xml file

Hi i have a php script that works 100% however i don't want this to run on php because of server limits etc. Ideally if i could convert this simple php script to a shell script i can set it up to run on a cron. My mac server has curl on it. So i am assuming i should be using this to download the... (3 Replies)
Discussion started by: timgolding
3 Replies

7. Shell Programming and Scripting

How to download file without curl and wget

Hi I need a Shell script that will download a zip file every second from a http server but i can't use neither curl nor wget. Can anyone will help me go about this task ??? Thanks!! (1 Reply)
Discussion started by: rubber08
1 Replies

8. Shell Programming and Scripting

curl script to download files from Secured HTTPS server?

curl -# -v -d "sendusername=myname&password=mypassword&wheretogo=download.php" -L -o test.zip http://www.ims-dm.com/cgi/securedownload.php?p=HIREFTPM\&prodtype=hire/test.zip * About to connect() to www.ims-dm.com port 80 * Trying 209.61.193.139... connected * Connected to www.ims-dm.com... (1 Reply)
Discussion started by: laknar
1 Replies

9. Shell Programming and Scripting

download an html file via wget and pass it to mysql and update a database

CAN I download an html file via wget and pass it to mysql and update a database field? (8 Replies)
Discussion started by: mapasainfo
8 Replies

10. Shell Programming and Scripting

Shell Script for Upload/download files using cURL

hi please help me out here, i want to use curl command in shell script to test web pages, what i have is an opening page, when i click on a button on opening page, the next page comes up and then i have to upload a file n then click another button to submit and then comes the output page,... (2 Replies)
Discussion started by: Olivia
2 Replies
Login or Register to Ask a Question