cron Error: bad username; while reading /etc/cron.d file on Linux

Posted on in Categories , , , , , last updated August 22, 2016

I am getting the following error in my cron job log file /var/log/cron.log:
       Aug 22 01:59:01 server2 cron[7510]: Error: bad username; while reading /etc/cron.d/backups
I have job entry as follows to run a job at 00:50 every day for root user:
       50 0 * * * /etc/cron.d/backups
How do I fix this problem on Linux or Unix-like system?

You are getting this error because you forgot to set name of the user to run a cron job:

Syntax

1 2 3 4 5 USERNAME /path/to/command arg1 arg2
Where,

    1: Minute (0-59)
    2: Hours (0-23)
    3: Day (0-31)
    4: Month (0-12 [12 == December])
    5: Day of the week(0-7 [7 or 0 == sunday])
    USERNAME - Name of the user
    /path/to/command – Script or command name to schedule

The correct syntax is as follows for root user to run a cron job at 00:50 every day:

50 0 * * * root /etc/cron.d/backups

To run as vivek user:

50 0 * * * vivek /etc/cron.d/backups

See our tutorial “HowTo: Add Jobs To cron Under Linux or UNIX?” for more information.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.