233

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.

BenMorel
  • 34,448
  • 50
  • 182
  • 322

5 Answers5

439

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 * * * ....
Marv
  • 3,517
  • 2
  • 22
  • 47
Marc Simon
  • 5,415
  • 1
  • 19
  • 21
  • Although the hour 22 might be relatively save, please consider the first case of [this question](https://stackoverflow.com/q/52354269/562769) – Martin Thoma Sep 16 '18 at 12:53
  • @MartinThoma always try `man cron` first, you should find what you are looking for. – Marc Simon Sep 17 '18 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 '19 at 18:10
  • I upvoted this answer but I did know this rule... anyway I wanted to confirm my silent knowledge :D – rnrneverdies May 19 '20 at 00: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 * * *

tripleee
  • 175,061
  • 34
  • 275
  • 318
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

Peanut
  • 3,753
  • 3
  • 31
  • 45
jaypal singh
  • 74,723
  • 23
  • 102
  • 147
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"

z atef
  • 7,138
  • 3
  • 55
  • 50
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