Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The following should be done in a bash script:

curl --digest --user schmijos https://bitbucket.org/u/p/get/tip.zip -o tip.zip

How can I automatically submit a password to curl when it asks for it? Since I don't want to see the password in any logfile, I won't do the following:

curl --digest --user schmijos:$password https://bitbucket.org/u/p/get/tip.zip -o tip.zip
share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

Use empty:

With the password safely stored (it's a way of saying...)

$ echo password > pwd-file

Start process with empty. (You would omit -L log in the real case.)

$ empty -f -i fifo1 -o fifo2 -L log curl -u user http://example.com

Send the contents of pwd-file to empty's input pipe, which the process sees as both its stdin and /dev/tty.

$ empty -s -c -o fifo1 < pwd-file

This is what happened in the pseudo terminal:

$ cat log
<<<Enter host password for user 'user':>>>password
<<<
share|improve this answer
    
+1 - This seems to be a solid solution. But I would appreciate if the tools were built-in or available in a standard linux environment. –  Josua Schmid Nov 20 '12 at 14:52
add comment

Curl can read passwords from ~/.netrc. Add a line like this to ~/.netrc:

machine bitbucket.org login schmijos password swordfish

and run

curl --netrc --digest --user schmijos https://bitbucket.org/u/p/get/tip.zip -o tip
share|improve this answer
    
~/.netrc does not store encrypted passwords. Alternatives like crypt have to be used. –  Josua Schmid Nov 20 '12 at 14:34
    
@JosuaSchmid If you encrypt the password, you'll have to enter the decryption password. You can put .netrc on an encrypted filesystem, that's an orthogonal concern. Did you want to get a password prompt if necessary? I didn't get that impression from your question. –  Gilles Nov 20 '12 at 17:08
    
You are right. I don't want the password to be stored (in any insecure way). –  Josua Schmid Nov 20 '12 at 19:41
    
@JosuaSchmid Define insecure. If you don't want the password stored at all, why aren't you typing it when Curl prompts you to? –  Gilles Nov 20 '12 at 20:19
    
The script should be executed in background. –  Josua Schmid Nov 21 '12 at 7:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.