199

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
  • 30,280
  • 40
  • 163
  • 285

5 Answers5

400

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,303
  • 2
  • 18
  • 42
Marc Simon
  • 4,783
  • 1
  • 16
  • 20
  • 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
  • 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
162

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
  • 139,311
  • 24
  • 207
  • 268
64

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

0 22 * * *

enter image description here

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

Source: softpanorama.org

Peanut
  • 3,195
  • 2
  • 27
  • 43
jaypal singh
  • 67,706
  • 21
  • 93
  • 138
26

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
  • 5,570
  • 3
  • 41
  • 40
1

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