under debian as a root (using su -)

First of all there is already a job inside the server (done by someone else), when I type

crontab -e

I get

# m h  dom mon dow   command
* * * * * sh /opt/somescript.sh

It executes exery minute.

Anyway, I am trying to add a scheduled job to the crontab: I want tried to add a second job that will be executed every day at 00:30 am.

30 0   * * *    sh /opt/newscript.sh

I have two problems:

  • I am not able to edit the crontab with crontab -e
  • Is my newscript scheduling right ?

your scheduling is right. i'm not sure why you can't edit the crontab. do you get any error message?


If you're getting something like:

crontab: you are not authorized to use cron.  Sorry.

Add your username to /etc/cron.allow (or /etc/cron.d/cron.allow, depending on your setup).

You didn't mention what system you're running on, but several commercial Unixen default to using ed as the editor, instead of something sensible like vi. Set EDITOR=vi and try again:

$ EDITOR=vi crontab -e

Which will use vi as your editor. Replace vi with emacs or even [shudder] pico, whatever you're most comfortable with.

Another option is to use the file form of crontab:

$ crontab /tmp/ctab

Which will assign the contents of the file /tmp/ctab to the crontab for the current user. You can then edit /tmp/ctab (the name is not important) with whatever editor you like that can save as plain text: vi, emacs, Xcode, eclipse, whatever. First, do:

$ crontab -l > /tmp/ctab

To get a copy of the current crontab, so you can add to it (the crontab FILE form replaces the current crontab), then do:

$ crontab /tmp/ctab

To import the contents of /tmp/ctab.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy