1

Is there a way to get cron to run with an updated version of Bash that's been installed?

My OS came with Bash 3.x installed stock and I've upgraded it to 5.x with macports.

When I query bash --version from a terminal.app window the 5.x version is reported.

If I run the same query from within a cron job: * * * * * /temp/test_bash.sh >> /tmp/test_bash.log 2>&1 the 3.x version which came stock with the OS is reported.

MacOS 10.10.5

2
  • Cron runs outside the normal shell, so you just need to put the full path for all executables in your script. Everything you mention is great backstory, but what is the command you are running and what results make you think it’s failing? An edit detailing something concrete being run would help us help you (like what command are you invoking to check or change the tab? ).
    – bmike
    Nov 1 '20 at 11:25
  • @bmike I'm running bash --version from terminal, and from cron. In the case of the cron job it's routed to a log file. Updated the post to reflect the logfile part. Please let me know if there are other details you'd find helpful.
    – Scottmeup
    Nov 1 '20 at 11:51
1

This should be easy to sort.

From your shell, examine the full path of the bash you prefer

which bash

Then edit your script in tmp to call the same path to bash (or your script has to source in the dot files, but it’s custom to just make each item in cron know the full proper path and not depend on startup and login files as that is much more light weight for cron)

I’ll end with one last link on good customs for cron environment being intentionally different than an interactive shell.

1
  • As OP is using macports the path is /opt/local/bin
    – mmmmmm
    Nov 1 '20 at 15:23

You must log in to answer this question.

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