7

I want to create a cronjob that every X time goes to open a webpage.

This webpage is password protected by .htaccess (user=admin, passwor=pass). The instruction I give is the following:

wget --user=admin --password='pass' http://www.mywebsite.com/test.php

But cron gives me the following error:

--2012-05-02 10:14:01--  http://www.mywebsite.com/test.php
Resolving www.mywebsite.com... IP
Connecting to www.mywebsite.com|IP|:80... connected.
HTTP request sent, awaiting response... 401 Authorization Required
Reusing existing connection to www.mywebsite.com:80.
HTTP request sent, awaiting response... 403 Forbidden
2012-05-02 10:14:01 ERROR 403: Forbidden.

I have also tried doing:

wget admin:pass@http://www.mywebsite.com/test.php

but with similar errors. How can I solve? Thank you in advance for your help.

Lesleyvdp
  • 313
  • 2
  • 14
Avionicom
  • 191
  • 2
  • 5
  • 19
  • It looks like the wrong password or username is reaching the server. Can you run the `wget` command successfully from a shell prompt, i.e. without using cron? – Anders Lindahl May 02 '12 at 08:35
  • Anders, I receive the same error also using shell prompt. But the password is correct, because through the browser it works. – Avionicom May 02 '12 at 08:40
  • Then your password must contain some special character that has to be encoded or escaped properly - Does it contain something like `$`, `\ `, `!`, `"` ...? – Anders Lindahl May 02 '12 at 08:48
  • no, the password is very simple, composed by only letters – Avionicom May 02 '12 at 08:51
  • 1
    Then it is a good time to take a sniffer and compare the http traffic in the browser and from wget. The `Authorization:` header should be the same in both cases. Notice that there might be other things that cause this problem, for example restrictions on ip or useragent... – Anders Lindahl May 02 '12 at 08:59
  • What kind of authorization do you use? Basic, Digest, or something else? Could you post the htaccess? – Gerben May 02 '12 at 18:55
  • 2
    Hi, my VPS provider given me the solution to use -U firefox: `wget -U firefox --user=admin --password='pass' http://www.mywebsite.com/test.php` and now it works – Avionicom May 03 '12 at 10:13
  • @Gerben here is my .htaccess: `AuthName "Area Protetta" AuthType Basic require valid-user AuthUserFile "/xxx/.htpasswds"` – Avionicom May 03 '12 at 10:17
  • The solution using -U firefox above works if you remove quotes from the password. – Casey Hungler Aug 13 '16 at 17:28

3 Answers3

2

wget --user admin --password pass http://www.mywebsite.com/test.php

Opens every minutes a website with a htaccess password

*/1 * * * *  wget -O /dev/null --user admin --password pass "http://www.mywebsite.com/test.php" > /dev/null 2>&1
1

You are making a small mistake.

keep the http:// before the url.

You have

admin:pass@http://www.mywebsite.com/test.php

Change it to

http://admin:pass@www.mywebsite.com/test.php

Hope that works.

Jnanaranjan
  • 1,304
  • 15
  • 31
0

Add auth parameter to url. This works for me when call url directly.

http://yoururl.ext?auth=id:psw

I don't know how much secure it is...