Cron ignoring an update to crontab

5,101

Solution 1

When you say "the crontab" you're not being specific. You should say which one you mean. However, based on the contents, it looks like /etc/crontab. Since that file does have a user field, it doesn't make sense that you'd get that error. My bet is that there's a user crontab that has that line in it. User crontabs don't contain user fields.

The proper thing to do is not to change that line in /etc/crontab. There may be other jobs it runs.

You can edit that file and the files in the /etc/cron.* subdirectories using any editor. You can specify the editor you want to use when you use crontab -e by setting the EDITOR environment variable.

You should use crontab -e to edit user crontabs (including root's). Remove the user field or remove that line in the user crontab where it appears (not /etc/crontab). User crontabs don't have a user field, but the system crontabs do.

User crontabs are located in /var/spool/cron/crontabs. You can sudo grep for the line to find out which file has the stray line. Again, only use crontab -u username -e to edit the user crontab.

Solution 2

Check the manpage on your system for crontab(5) (man 5 crontab), especially under the "EXAMPLE SYSTEM CRON FILE" section. Only the /etc/crontab file includes a username field. Non-system user crontabs do not include this field. If you want to edit /etc/crontab, then use a text editor, not the crontab(1) command.

Share:
5,101

Related videos on Youtube

GJ.
Author by

GJ.

Updated on September 17, 2022

Comments

  • GJ.
    GJ. over 1 year

    I've commented out a line in the crontab on a debian server, which I guess was there by default yet was causing me to get error emails every hour:

    # m h dom mon dow user  command
    17 *   * * *   root    cd / && run-parts --report /etc/cron.hourly
    

    However, the error emails keep coming in as if it hasn't been commented out. The error emails:

    Subject: Cron <root@(none)> root    cd / && run-parts --report /etc/cron.hourly (failed)
    /bin/sh: root: not found
    

    Any ideas?

    • Patrick
      Patrick about 13 years
      wouldn't be easier to sudo vi crontab, that way you are modifying root's crontab?
    • GJ.
      GJ. about 13 years
      @patrick: I'm logging in as root, so there's no sudo..
    • Jacob Hume
      Jacob Hume about 8 years
      Just in case it helps anyone else, I received this error because I ran crontab -e /etc/crontab, which DOES NOT safely edit /etc/crontab. It creates a duplicate that generates this error, and can be removed by running crontab -r.