Is there a way to pass the username and password from a file instead of the command line via --user and --password?
Background: I want to run wget via cron and don't want the username/password show up in process view
Is there a way to pass the username and password from a file instead of the command line via --user and --password?
Background: I want to run wget via cron and don't want the username/password show up in process view
I'm surprised nobody mentioned the
.netrc
file. First create the file if it doesn't exists and set safe permissions:Then you can add the hostname, username and password all on one line:
Then when you do
wget https://example.com
and the server responds with401 Authorization Required
, wget will retry with the username and password from the~/.netrc
file.When using this from cron make sure you have the right
HOME
directory. Often cron setsHOME=/
(in that case you would have to create the file as/.netrc
, but it's better to set a properHOME
at the beginning of your script, likeexport HOME=/root
).You can specify multiple hosts in
~/.netrc
, one per line. More info inman netrc
.Use a
.wgetrc
file (GNU manual) in which you can set username and passwords for either or both ftp and http.To use the same credentials for both specify
or individually
In many regards curl can be a better choice. Wget became a bit stale over time.
curl's -n switch can be used for this task: http://curl.haxx.se/docs/manpage.html#-n