Error:
Iam 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?
Solution:
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
document.currentScript.parentNode.insertBefore(s, document.currentScript);