I am learning how to use cron. I wrote some simple code in my crontab

# m h  dom mon dow   command
*/1 * * * * echo "1 minute"> ~/Document/cronoutput

I expected it to print the words every minute, but it does not. Then I check a page. I run the following command

ps -ef | grep cron | grep -v grep

it returns

root     21430     1  0 13:24 ?        00:00:00 cron

after a few second, I rerun the command again:

root     21430     1  0 13:24 ?        00:00:00 cron

I suppose cron does not count elapsed time since it always shows 00:00.

What may be the problem and how to fix it?

  • 1
    does the command work from the command line? – hymie Oct 31 '14 at 17:19
  • The time here is the amount of CPU time used by the cron process. Since cron requires a negligible amount of CPU time, it'll stay at 0 for a while. This is normal. Have you set up local email? If a command fails, you'll receive an email to your local account, but some OSes don't set up local email by default or don't show them to you. – Gilles 'SO- stop being evil' Oct 31 '14 at 23:41

You've got it half right, but your syntax is incorrect. To run a cronjob every minute, enter asterisks in every field

# m h dom mon dow   command
  * * * * * echo "1 minute"> ~/Document/cronoutput 

If you look in your syslog logs you'll probably see an error along the lines of syntax error: this crontab will be ignored

The syntax you're using works, just not for every minute.

Every 2 hours

# m h dom mon dow   command    
  0 */2 * * * /path-to-script

Every 2 days

# m h dom mon dow   command
  0 0 */2 * * /path-to-script

Every 2 months

# m h dom mon dow   command
  0 0 0 */2 * /path-to-script

Try out same in /tmp directory, it must work:

*/1 * * * * echo "1 minute" > /tmp/cronoutput

If you try command from commandline, it will deny you with the permission problem.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.