235

I had entered:

* 22 * * * test > /dev/null

However, I am being notified via email that this is running every minute. I am confused I guess because I thought this was correct for what I am wanting.

1

5 Answers 5

441

It's running every minute of the hour 22 I guess. Try the following to run it every first minute of the hour 22:

0 22 * * * ....
4
  • Although the hour 22 might be relatively save, please consider the first case of this question Sep 16, 2018 at 12:53
  • @MartinThoma always try man cron first, you should find what you are looking for.
    – Marc Simon
    Sep 17, 2018 at 15:25
  • 1
    Remember to check the system's date, it happened to me to set crontab to start a job at 22, but it actually started at 23 because the system was UTC (so 22 for the system was 23 for me in GMT).
    – nnsense
    Apr 24, 2019 at 18:10
  • I upvoted this answer but I did know this rule... anyway I wanted to confirm my silent knowledge :D May 19, 2020 at 0:57
189

Here are some more examples

  • Run every 6 hours at 46 mins past the hour:

    46 */6 * * *

  • Run at 2:10 am:

    10 2 * * *

  • Run at 3:15 am:

    15 3 * * *

  • Run at 4:20 am:

    20 4 * * *

  • Run at 5:31 am:

    31 5 * * *

  • Run at 5:31 pm:

    31 17 * * *

1
  • 1
    Good examples to understand the cron syntax Aug 10, 2020 at 4:42
69

To run once, daily at 10PM you should do something like this:

0 22 * * *

enter image description here

Full size image: https://i.stack.imgur.com/BeXHD.jpg

Source: softpanorama.org

1
  • 6
    Apologies for the bad picture size. Jan 20, 2012 at 8:59
34

Here is what I look at everytime I am writing a new crontab entry:

To start editing from terminal -type:

 zee$ crontab -e

what you will add to crontab file:

0 22 * * 0  some-user /opt/somescript/to/run.sh

What it means:

[ 
+ user => 'some-user',      
+ minute => ‘0’,             <<= on top of the hour.
+ hour => '22',              <<= at 10 PM. Military time.
+ monthday => '*',           <<= Every day of the month*
+ month => '*',              <<= Every month*
+ weekday => ‘0’,            <<= Everyday (0 thru 6) = sunday thru saturday
] 

Also, check what shell your machine is running and name the the file accordingly OR it wont execute.

Check the shell with either echo $SHELL or echo $0

It can be "Bourne shell (sh) , Bourne again shell (bash),Korn shell (ksh)..etc"

1
  • Your command shows 0 for the weekday, but your explanation shows it as *
    – Frak
    Feb 14, 2021 at 5:59
4

The syntax for crontab

* * * * * 

Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute

Your syntax

* 22 * * * test > /dev/null

your job will Execute every minute at 22:00 hrs all week, month and year.

adding an option (0-59) at the minute place will run it once at 22:00 hrs all week, month and year.

0 22 * * * command_to_execute 

Source https://www.adminschoice.com/crontab-quick-reference