[bash] How to run cron once, daily at 10pm

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.

This question is related to bash cron system scheduled-tasks

The answer is


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 * * *


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


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


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"


Examples related to bash

Comparing a variable with a string python not working when redirecting from bash script Zipping a file in bash fails How do I prevent Conda from activating the base environment by default? Get first line of a shell command's output Fixing a systemd service 203/EXEC failure (no such file or directory) /bin/sh: apt-get: not found VSCode Change Default Terminal Run bash command on jenkins pipeline How to check if the docker engine and a docker container are running? How to switch Python versions in Terminal?

Examples related to cron

How to run a cron job inside a docker container? Run CRON job everyday at specific time How to run a cron job on every Monday, Wednesday and Friday? Spring cron expression for every day 1:01:am How to run a cronjob every X minutes? CronJob not running Scheduling Python Script to run every hour accurately How to set a cron job to run every 3 hours Execute PHP script in cron job How to create a Java cron job

Examples related to system

cannot convert 'std::basic_string<char>' to 'const char*' for argument '1' to 'int system(const char*)' How to code a very simple login system with java Convert R vector to string vector of 1 element How to run cron once, daily at 10pm Java system properties and environment variables A terminal command for a rooted Android to remount /System as read/write Difference between subprocess.Popen and os.system How can I store the result of a system command in a Perl variable? Adding system header search path to Xcode How can I check the system version of Android?

Examples related to scheduled-tasks

How to restart a windows service using Task Scheduler Run exe file with parameters in a batch file Scheduling Python Script to run every hour accurately How to schedule a function to run every hour on Flask? I need a Nodejs scheduler that allows for tasks at different intervals Windows Task Scheduler doesn't start batch file task Windows Scheduled task succeeds but returns result 0x1 Powershell script does not run via Scheduled Tasks My C# application is returning 0xE0434352 to Windows Task Scheduler but it is not crashing Scheduling recurring task in Android