Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Where is your wget? Just supply the full path in your crontab. – slhck Aug 6 '12 at 21:01
up vote 6 down vote accepted

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

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.

share|improve this answer
/usr/bin/which: illegal option -- - is what I get when I run which – atb Aug 6 '12 at 21:10
@allanb Is that what you get when you run which wget? Are you sure? – slhck Aug 6 '12 at 21:13
MacBook-Pro:~ allan$ which wget /usr/bin/which: illegal option -- - usage: which [-as] program ... – atb Aug 6 '12 at 21:44
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 – Markus Orreilly Aug 6 '12 at 22:25
In any case, using the whole path worked for me. – atb Aug 7 '12 at 13:52

To find out where a certain command is located try:

which wget


which <certain-command>

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

linux-dgr7:~ # sudo which 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.



share|improve this answer
You shouldn't need sudo for which. – slhck Aug 6 '12 at 21:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .