crontab - /bin/sh: wget: command not found

3

1

I want to set up a crontab on my Macbook Pro running Lion. I run the usual crontab -e and provide a quick job to see if everything is working ok ---

*/10 * * * * wget -O - -q -t 1 http://site.local/cron.php

10 minutes later I see I've got some "mail" from the system stating ---

/bin/sh: wget: command not found

I do have wget installed as I can run the program from the command line

How do I fix this error? Does my crontab or .bash_profile require a shebang?

Allan Thomas

Posted 2012-08-06T20:48:39.933

Reputation: 313

2Where is your wget? Just supply the full path in your crontab. – slhck – 2012-08-06T21:01:15.023

Answers

10

It's probably something to do with your environment being different when it's run as a cron job (ie the PATH environment variable is different than what you're using from a bash terminal).

In your bash terminal, use which to figure out which wget is being used:

laptop [ ~ ]: which wget
/opt/local/bin/wget

Then use the full path in the cron job:

*/10 * * * * /opt/local/bin/wget -O - -q -t 1 http://site.local/cron.php

For cron jobs, I usually have it run a bash script instead of specifying the command directly in the crontab. It's a bit easier to debug and keeps the crontab a bit cleaner.

d0c_s4vage

Posted 2012-08-06T20:48:39.933

Reputation: 271

/usr/bin/which: illegal option -- - is what I get when I run which – Allan Thomas – 2012-08-06T21:10:17.980

@allanb Is that what you get when you run which wget? Are you sure? – slhck – 2012-08-06T21:13:22.593

MacBook-Pro:~ allan$ which wget /usr/bin/which: illegal option -- - usage: which [-as] program ... – Allan Thomas – 2012-08-06T21:44:09.090

That's really weird. You could try using mac's spotlight search with this: mdfind -name wget | grep -E "/wget$" might get more answers than one though – d0c_s4vage – 2012-08-06T22:25:33.253

In any case, using the whole path worked for me. – Allan Thomas – 2012-08-07T13:52:22.340

2

To find out where a certain command is located try:

which wget

or

which <certain-command>

The output should provide the path of the executable. For example:

linux-dgr7:~ # sudo which wget
/usr/bin/wget 

then change the entry like so:

*/10 * * * * /usr/bin/wget -O - -q -t 1 http://site.local/cron.php

If the wget does not come up after doing which... you should add the location to the PATH variable.

PATH=$PATH:/where/ever/path/is

or

PATH=$PATH:/opt/wget

Jay

Posted 2012-08-06T20:48:39.933

Reputation: 21

2You shouldn't need sudo for which. – slhck – 2012-08-06T21:31:36.493