Hi Guys,
I have set up a cron job on a Centos server that is supposed to execute a script that looks for SMS messages in a queue and processes them. My crontab file is under /etc/crontab. The job is supposed to be run after every 5 minutes. The command I have added to the crontab file is 01 * * * * root /usr/local/bin/ to make it run after every minute. However, when I look at the cron log, the job is running after every one hour. Please help me figure out whether its my command that is wrong because as I understand it the command 01 * * * * root /usr/local/bin/ is supposed to execute the script after every one minute.

Dani AI

Generated

Short clarification and a few practical checks based on what and found.

In the system crontab (/etc/crontab) the time fields come first, then the user, then the command: minute hour day month weekday user command. A literal 01 in the minute field fixes the job to run at minute 1 of every hour (hence the behavior you saw). It does not mean "every minute". For regular intervals use step notation for the minute field instead of a fixed value.

A safe, common way to run the script every 5 minutes from the system crontab and capture output is for example:

*/5 * * * * root /usr/bin/perl /usr/local/bin/readsms.pl >> /var/log/readsms.log 2>&1

Notes and quick troubleshooting

  • Use absolute paths: call the interpreter explicitly or ensure the script has a correct shebang and is executable.
  • Remember the user field is required in /etc/crontab; in a per-user crontab (crontab -e) you omit the user.
  • Check cron is running: systemctl status crond or service crond status depending on your CentOS version.
  • Inspect cron logs: /var/log/cron or journalctl -u crond to see job starts and any errors.
  • If nothing appears in logs, try a simple test job that appends a timestamp to a file to confirm cron scheduling is working.
  • If SELinux is enabled, audit denials can stop scripts; check /var/log/audit/audit.log or use ausearch/sealert tools.

Those checks cover the common pitfalls: wrong time field, missing user field, environment/paths, permissions, and SELinux.

Recommended Answers

All 2 Replies

It appears the the zero is being read as minutes and the one as the hour. I doubt any of the cron programmers allowed for someone entering "01" instead of just "1".

P.S The 01 was added automatically even though in the command I had put only 1 without a zero. I was able to sort it out. It seems that if you just want the job to be executed every minute, you do not have to specify the 1, you just type in the command as * * * * * <owner> /<path to script>. And I think this makes sense because a minute is the least time you can specify for intervals of job executions.
Thanks for the reply woooee; nice name :) by the way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.