0

I was hoping for a little guidance with a problem that has me beaten.

I want to use cronjobs on a Mac Mini running macOS Monterey, but it is not behaving as it does on other machines I have running Debian.

When I run crontab -l, I get what you would expect, in this case;

# m  h  dom mon dow   command

which is how I left it a few versions of macOS ago.

However, when I run crontab -e, I get the rather more unexpected;

crontab: $EDITOR: No such file or directory
crontab: "$EDITOR" exited with status 1

The EDITOR variable is set to /usr/local/bin/nvim, and nvim works perfectly as I am using it now to draft this post.

The only things a broad Google search has shown me are:

  1. I needed to ensure that cron was granted Full Disk Access in macOS Security settings

and:

  1. that this does not seem to be a normal issue people have encountered.

Could someone point me towards a solution, please?

6
  • 1
    Try another editor maybe e.g. export EDITOR=/usr/bin/vi Commented Oct 25, 2022 at 21:23
  • I did try vim and vi and the result was the same
    – keith56
    Commented Oct 25, 2022 at 21:50
  • 2
    What exact command are you running to create EDITOR? Commented Oct 25, 2022 at 21:56
  • 1
    What does "export | grep EDITOR" say? Commented Oct 26, 2022 at 16:41
  • @mmmmmm Now I‘m curious: why does this matter?
    – nohillside
    Commented Jan 25, 2023 at 18:25

2 Answers 2

3

The error message you get indicates that the EDITOR variable is set to the literal value $EDITOR:

$ EDITOR='$EDITOR' crontab -e
crontab: $EDITOR: No such file or directory
crontab: "$EDITOR" exited with status 1

To fix run

export EDITOR=/usr/local/bin/nvim
export VISUAL="$EDITOR"
/usr/bin/crontab -e

and check the init files of your shell for the wrong definition.

8
  • Sadly, you are mistaken. That is the definition of EDITOR as it appears in my .bashrc.
    – keith56
    Commented Oct 26, 2022 at 18:04
  • ... nevertheless I ran both the lines in your suggestion, but the problem persists. Thanks you for trying though.
    – keith56
    Commented Oct 26, 2022 at 18:05
  • ..... however, I have just edited out the lines refering to export EDITOR and export VISUAL and all now works. If these variables are blank then it works? Odd that this is not a problem under Linux. Anyway I will ponder on the facts, but your solution turned out to work, so thank you very much. I am very grateful.
    – keith56
    Commented Oct 26, 2022 at 18:12
  • 3
    @keith56 VISUAL='$EDITOR' is working in neither bash nor zsh, on neither macOS nor Linux. I suspect that crontab on macOS uses VISUAL, crontab on Linux uses EDITOR, so the problem only shows on macOS.
    – nohillside
    Commented Oct 26, 2022 at 18:39
  • 3
    To make it explicit: VISUAL='$EDITOR' with single quotes is not what you want. You need double quotes: VISUAL="$EDITOR". Commented Oct 26, 2022 at 20:50
1

TL;DR;

setting $VISUAL to /usr/bin/nano makes the crontab -eworking for me!

Details

I ran in a similar issue on Monterey in zsh but it was due to SublimeText was configured as default editor:

echo $EDITOR
# output:
subl -w

When trying to edit the crontab of either user or root I got:

crontab -e # or
sudo crontab -e

# output
crontab: subl -w: No such file or directory
crontab: "subl -w" exited with status 1

Neither solutions from other suggestions worked:

  • to change the $VISUAL editor variable to subl -w
  • omitting the -w

or

  • editing the sudoers file via visudo helped not (to get visudo to work, I had to set both $EDITOR and $VISUAL to nothing)
export EDITOR=""
export VISUAL=""

actually the suggested line was already present!

Defaults env_keep += "EDITOR VISUAL"

Possible low level shell path issue

At the end it turns out to be related to the regular $PATH is not to be accessible by the crontab command. Even symlinks seemed not to work until I set the $VISUAL setting different from $EDITOR to /usr/bin/nano. Then it started working using nano with an explicit absolute path.

export VISUAL=/usr/bin/nano 

Standard $EDITOR Setting can be preserved

For crontab usage it is irrelevant if $EDITOR is set to nothing or subl -w, both are suitable!

IMPORTANT:

To make these changes permanent you have to put the export lines in your terminal startup file ( ~/.zshrc or ``~/.profile depending on your setup)

Make sure you granted Full Disk Access to crontab and cron in ``System Preferences```

  • Giving cron full disk access

    If you are using [[macOS]] [[Catalina]] (or higher) you will also need to give the cron service Full Disk Access.
    • Go to the System Preferences and select Security & Privacy.
    • In the left-hand column, select Full Disk Access, click thepadlock icon, enter your password and click on the plus icon for a file browser to appear.
    • When the file browser appears, press ⌘ ⇧ G to open the go to folder dialog and type: /usr/sbin/cron
    • Press Go to close the dialog and confirm that cron appears in the list of apps that have full disk access in the Security & Privacy window.
    • Repeat with /usr/bin/crontab

You must log in to answer this question.

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