0

I am trying to set up a cronjob to run every minute with the following command:

crontab * * * * * sh /Users/username/Downloads/reddit-notifications-master/notifyer.sh

notifyer.sh has the following contents:

#!/bin/zsh

python3 /Users/yogesh/Downloads/reddit-notifications-master/reddit_notifications.py

When I run the command it says:

"LICENSE":0: bad minute
crontab: errors in crontab file, can't install

Has anyone seen this before? Tried googling but can't find anything on the LICENSE: 0 error.

orange
  • 279
  • 1
    crontab takes a filename (to read crontab entries from) as an argument, not a raw crontab entry. It also replaces the current crontab (deleting any current entries), rather than just adding new entries to it. I'd recommend using crontab -l to see the current contents; and then possibly crontab -e to edit the current crontab, although the default editor is vi and if you're not familiar with it, it's going to be really hard to use. – Gordon Davisson May 13 '20 at 01:27
  • crontab -l outputs nothing. The crontab contents are currently empty. – orange May 13 '20 at 01:28
  • In that case, try contab - (note the space and single dash) by itself, then * * * * * sh /Users/username/Downloads/reddit-notifications-master/notifyer.sh on the next line (as input to the crontab program), then Control-D on the next line after that to indicate end-of-input. – Gordon Davisson May 13 '20 at 01:30
  • a couple things... crontab won’t generate a “license error,” that’s got to be coming from your command. What happens if you run the command manually. Second, you’re starting an sh shell to then create a ZSH shell with the shebang in your script. Why not just call the script and let the shebang (#!/bin/zsh) handle the shell? – Allan May 13 '20 at 01:50
  • Also, cron has been deprecated in favor of launchd. You might want to start migrating to that. See: https://apple.stackexchange.com/a/249452/119271 – Allan May 13 '20 at 01:53

1 Answers1

2

You can't add a crontab entry by just running crontab <entry details>. In your case the shell expands the * with whatever filenames it finds in the current directory (which seems to be a file called LICENSE, replace crontab by echo to see what happened to the other *'s).

To add new entries to the crontab file run

export EDITOR=nano
crontab -e

add the line

* * * * * /Users/username/Downloads/reddit-notifications-master/notifyer.sh

directly to the file and save it, then exit the editor again. You can verify that it got added by running crontab -l.

Some additional things to consider:

  • Run chmod +x /Users/username/Downloads/reddit-notifications-master/notifyer.sh to make sure the script is executable
  • Run type python3 in your shell and use the full path you get within notifyer.sh to avoid issues with python3 not being in PATH
  • If notifyer.sh is only used to launch the Python script you don't need the script at all, you can just add

    * * * * * /path/to/python3 Users/yogesh/Downloads/reddit-notifications-master/reddit_notifications.py
    

    to your Crontab instead.

nohillside
  • 100,768