Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 have this in my crontab:

PATH=/usr/bin:/usr/local/bin:$PATH
*/1 * * * * /usr/bin/env bash > ~/cron.log 2>&1

The ouput in cron.log is the following:

/usr/bin/env bash: No such file or directory

/usr/bin/env as well as /bin/bash both exist. And I can also run this command from the same user to whom this crontab belongs without any errors. I also tried adding

SHELL=/bin/bash

to the top of the crontab. No effect. Don't have a clue what's going on. Also this:

*/1 * * * * which bash > ~/cron.log 2>&1

shows nothing at all in the log file. This is everything I have in my crontab for this user, nothing else.

share|improve this question
    
Is that a typo, in your last example, shouldn't it read `which bash`, instead of which bash? – BenjiWiebe Feb 15 '13 at 2:05

Since your script that cron runs starts with #!/usr/bin/env bash (right?), all you need to do in your crontab is:

*/1 * * * * /path/to/script > ~/cron.log 2>&1

And make sure that the script actually outputs something; if your script is completely quiet, your log file will be empty.

share|improve this answer
    
I had to add PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/‌​usr/local/games" as well. I had to login to the server as root (not sudo) to figure out what the root path was by default. Apparently cron is too dumb to use the user's default profile – chovy Mar 5 at 10:39

Turns out, I shouldn't have had this line:

PATH=/usr/bin:/usr/local/bin:$PATH

Removing it from crontab fixed the issue.

share|improve this answer
    
Combination of yours an @benjiwiebe's solved my problem. Cron is really too dumb to know anything. Its default path is basically 2 directories. – chovy Mar 5 at 10:45

Am not sure what exactly you're trying to do, but for me:

# which bash
/bin/bash

So try

/usr/bin/env /bin/bash /path/to/some/script > ~/cron.log 2>&1
share|improve this answer
    
One of the scripts that I run with cron (rvm-exec) has #!/usr/bin/env bash at the top of it and I can't really change it, because it breaks everything. I realized that the problem in this particular case is with cron, not rvm, since cron doesn't even know where bash is. – snitko Feb 15 '13 at 0:52
3  
It completely defeats the purpose to use /usr/bin/env /bin/bash; /usr/bin/env searches the PATH for bash; you use /usr/bin/env to find bash when you are not sure where bash is at. – BenjiWiebe Feb 15 '13 at 2:04
    
just call bash at top of crontab – chovy Mar 5 at 10:45

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.