1

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.

1
  • Is that a typo, in your last example, shouldn't it read `which bash`, instead of which bash?
    – BenjiWiebe
    Feb 15, 2013 at 2:05

3 Answers 3

5

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.

1
  • 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, 2016 at 10:39
1

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

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

Removing it from crontab fixed the issue.

1
  • 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, 2016 at 10:45
-3

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
3
  • 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.
    – orion3
    Feb 15, 2013 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, 2013 at 2:04
  • just call bash at top of crontab
    – chovy
    Mar 5, 2016 at 10:45

You must log in to answer this question.

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