0

I have manually added a command to my crontab file (Monterey 12.6.9). Pretty simple; the crontab entry is something like:

0 10 * * * mv /Users/me/Desktop/test /Users/me/Desktop/test2

Which means, at 10am every day, do this rename.

But it simply doesn't work. Other commands in my crontab file work fine, which suggests that cron IS actually executing. I HAVE given the cron app "Full Disk Access" in Security & Privacy. That mv command works fine as a terminal command. Not sure where the cron log is, so I haven't pieced together what is happening. This is confusing. Advice?

1
  • 1
    How did you edit the crontab file?
    – Barmar
    Commented Sep 20, 2023 at 19:24

1 Answer 1

0

This works on my Ventura system, and it should work on your Monterey system...

I don't think cron has a "log file" per se, and so I'll suggest you get into the habit of creating and using a file to capture the output of stdout and stderr from all cron jobs. It's the best way to troubleshoot mysterious cron issues.

FROM:

0 10 * * * mv /Users/me/Desktop/test /Users/me/Desktop/test2

TO:

0 10 * * * mv /Users/me/Desktop/test /Users/me/Desktop/test2 >> /Users/me/Desktop/test_log 2>&1

The information in the file test_log should contain something useful, and suggest where the issue is. I suspect - in this case - it's something simple.

Here's the breakdown on the addition:

  • >> a redirect (with augmentation instead of replacement)

  • 2>&1 redirect stderr to stdout; effectively combines both streams into a single stream

Another good habit with crontab entries that name an executable file is to specify the full path to that executable. You'll get away with it when the executable is in the PATH, but it may not be obvious what cron's PATH actually is.

Yet another good habit with cron is to turn OFF the default MAILTO feature. This is done by adding this line at or near the top of your crontab:

MAILTO=""
12
  • Thank you. I will try that. Now I just noticed that the cron daemon has been mailing me an error message. It is /bin/sh: -c: line 0: unexpected EOF while looking for matching `)' /bin/sh: -c: line 1: syntax error: unexpected end of file What does that mean??? Again, everything else in my crontab file is running properly (these are from the scheduling for SuperDuper), and my new line is on something like line 5.
    – user637
    Commented Sep 20, 2023 at 2:25
  • @user637: Yeah - that's a fairly inconvenient default, but it's easy to eliminate it. I've edited my answer to explain.
    – Seamus
    Commented Sep 20, 2023 at 2:28
  • I entered that revised command aimed at a few minutes ago, and NOTHING came out. No test_log appeared on my Desktop. That crontab line is simply not being executed. Also, I don't see any edit in your answer that explains.
    – user637
    Commented Sep 20, 2023 at 2:34
  • Could you please edit your question to post a crontab entry that does work? IOW - a counter-example.
    – Seamus
    Commented Sep 20, 2023 at 2:43
  • 2
    @user637 See unix.stackexchange.com/questions/29578/…
    – Barmar
    Commented Sep 20, 2023 at 19:25

You must log in to answer this question.

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