3

How do I update shell programs like crontab for example? On my Mac I've got version from 29th of December 1993, but on a server linux machine that I am using version of crontab is much better in terms of usability since it's from 19th of April 2010.

I am running MacOS Mojave and my bash version is : GNU bash, version 5.0.2(1)-release (x86_64-apple-darwin18.2.0)

crontab on my Mac: Mac crontab on my Linux: Linux

  • How did you update your bash? – nohillside Feb 13 at 18:40
  • With homebrew (brew.sh). Once you install it run brew install bash. And once it's done you need to add your current shell's directory (check the directory of it by running which bash) to /etc/shells. And then finally change your shell by running change shell command : chsh -s "shell's directory you've added to /etc/shells" – Victor Feb 13 at 18:52
  • It was kind of a rhetoric question :-) – nohillside Feb 13 at 18:54
  • crontab is deprecated, by the way. You should be using launchd instead See man crontab – Allan Feb 13 at 21:50
  • A quick check of the source code for vixie crontab, available at Apple OpenSource, shows that crontab.c was modified in September of 2006. – fd0 Feb 14 at 15:02
1

Where is the executable?

command -v cron

The result shows /usr/sbin/cron. System Integrity Protection (SIP) protects the contents of /usr; thus we cannot affect a change anyway as long as SIP is enabled. You installed BASH via Homebrew, I take it. Searching Homebrew for cron-related formulae or casks reveals no candidates (brew search cron), perhaps for reasons given by @nohillside. Perhaps cron was a bad example and a better example might be vim. As you have discovered, one can utilize a package manager like Homebrew or Macports to install more recent software. For each installed package, Homebrew, at least, installs a symbolic link to wherever the executable was installed (/usr/local/Cellar/[...]); thus, we could utilize a shell alias or modify the PATH environment variable to utilize better versions of common software. I use the shell alias approach.

For example, my shell is zsh, and I have installed MacVim. If the symbolic link for MacVim's version of vim exists (-h), then define a new alias. Now, every time I execute vim, I am not executing the vim located in /usr/bin; rather, I am executing the vim located in /usr/local/bin. The below test and definition works the same for bash.

[ -h '/usr/local/bin/vim'  ] && alias vim='/usr/local/bin/vim'
[ -h '/usr/local/bin/view' ] && alias view='/usr/local/bin/view'

And then use the package manager to update the software periodically.

if brew update 2>/dev/null; then
    brew upgrade
    brew cleanup
    rm -rf "$(brew --cache)"
fi
  • Might be easier to put /usr/local/bin in front of /usr/bin in your PATH (and in /etc/paths), otherwise you need to define aliases for each command you install. Also, aliases don't work in scripts (well, at least not in bash, don't know about zsh). – nohillside Feb 13 at 19:37
  • Hi, and thanks for the note @nohillside. Yes, I alluded to the PATH approach. Myself, I don't use aliases in scripts - just the interactive shell. – Christopher Feb 13 at 19:42
  • @nohillside Oh! And we only need an alias if the same command already exists in the PATH before /usr/local. – Christopher Feb 13 at 19:50
3

The content of /usr/bin and friends is updated with each release of macOS, but usually the versions shipped by Apple are significantly older than what's available on Linux. There are various reasons for this, in a lot of cases it's related to changes in the GPL. In case of crontab it may also play a role that the use of cron is deprecated, launchd should be used instead.

If you want to update Unix binaries yourself

  • Use Homebrew (https://brew.sh)
  • Compile from source yourself and install in /usr/local/bin
  • When I tried brew install cron and brew install crontab it only said that no available formulas with those names. – Victor Feb 13 at 18:54
  • But like you've said I think I will start to use launchd instead, thanks! – Victor Feb 13 at 18:55
  • @Victor Yeah, looks like there is no formula for cron. You still can compile yourself, but I'm not sure it's worth the hassle. – nohillside Feb 13 at 18:56

You must log in to answer this question.

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