1

I know launchd is the way to go, but would really need to use cron in this situation.

I'm trying to run the following command through cron:

rclone copy /Users/x123/Downloads/torrents mega:torrents -q && rm -f /Users/x123/Downloads/torrents/*.*

This works ok on terminal, however when I go crontab -eand add it, it doesn't run.

I also tried adding the command to an .sh script, making executable and running it with cron, also no good.

I'm honestly at loss. I tried touching a file, and it works. For example:

*/5 * * * * touch ~/Downloads/torrents/Test1.txt

Creates the file just ok, however:

*/5 * * * * rclone copy /Users/x123/Downloads/torrents mega:torrents -q && rm -f /Users/x123/Downloads/torrents/*.*

Doesn't, neither does:

*/5 * * * * cd /Users/x123/ && ./script.sh (which the script contains the command)

Worth noting: cron, crontab have Full Disk access.

Should I take this inquiry to rclone forum? Any help understanding what's going on would be super appreciated!

So I learned a few things:

  1. When working with cron and it seems to not work, check your mail inbox, it helps!

  2. Always use full paths when dealing with cron

  3. If you instruct cron a command, and then decide to move all this to a script, check and recheck your script. In my case, I was so wrapped up in full paths, that I forgot about the command verbs!

  4. Thank you all guys for the continuous and great support. It's extremely valuable!

0

1 Answer 1

3

Absolute Paths

Use an absolute (full) path to rclone in the command.

cron executes commands in a simpler environment than when the same command is run from an interactive terminal session. This means most executables can not be found without their location being fully provided.

To find the path to rclone on your Mac, use the command:

which rclone

The output will be the path to use. If you have installed rclone using the Homebrew package manager, the path will likely be:

/usr/local/bin/rclone

See also cron and "command not found".

Try testing the rclone command without the rm command:

/usr/local/bin/rclone /Users/x123/Downloads/torrents mega:torrents -q

Globs

The * passed to rm will not be expanded; there is no shell involved to do the expansion. A shell script – with an absolute path – is likely easier to get working.

Shell Script

Consider writing the commands as a shell script and have cron call the script. Be sure to use absolute paths for every executable in the shell script and to pass the absolute path to the shell script in cron:

*/5 * * * * /bin/bash /Users/x123/Documents/myscript.sh
6
  • 2
    I also doubt whether rm -f /Users/x123/Downloads/torrents/*.* works as expected. It might be easer to put everything into a shell script (and use absolute paths there).
    – nohillside
    Nov 12, 2022 at 9:43
  • 1
    Also, use /usr/local/bin/rclone /Users/x123/Downloads/torrents mega:torrents -q > /tmp/cron.out 2>&1 to capture any output, and look at /tmp/cron.out afterwards to check for errors etc.
    – nohillside
    Nov 12, 2022 at 16:17
  • 1
    cron should be spamming your mailbox with error messages. Have you checked your mailbox?
    – fd0
    Nov 12, 2022 at 19:49
  • 1
    @fd0 INDEED IT DID. Thank you for reminding me something so basic in Unix but that I overlooked! This type of help is always appreciated :) Nov 12, 2022 at 22:19
  • 1
    Thanks @nohillside! I think fd0's recommendation actually did work. *** I was forgetting the verb on rclone *** . After so much dealing with the script and all, I forgot how to properly use rclone, sorry! Let's see what happens when I fix it. Nov 12, 2022 at 22:31

You must log in to answer this question.

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