Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
2  
Where is your wget? Just supply the full path in your crontab. –  slhck Aug 6 '12 at 21:01

2 Answers 2

up vote 4 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
/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.

share|improve this answer
    
/usr/bin/which: illegal option -- - is what I get when I run which –  allanb 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 ... –  allanb 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. –  allanb Aug 7 '12 at 13:52

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
share|improve this answer
1  
You shouldn't need sudo for which. –  slhck Aug 6 '12 at 21:31

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.