Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
Improve this question
I would like to run a cronjob every 5 hours.
Now it's 11:54pm..
Checking the crontab guru, this 0 */5 * * * seems to be correct, but the site also mentions something like this
next at 2022-01-07 00:00:00
I would like to know why? Does it mean it runs the script no matter what at midnight(00:00:00) ? Doesn't make sense.
The */5 syntax means "every 5 units, starting from 0". So, if you use it in the hour position, it will match hours 0, 5, 10, 15, 20.
I'm assuming what you actually want is a strict 5 hour interval. So after hour 20, you want the next run to be at 20 + 5 hours, so at 1AM not midnight. If that's correct, there isn't an easy way to make cron work like that. It can do even intervals of all divisors of 24 though: every 2 hours, every 3 hours, every 4 hours, every 6 hours, every 12 hours.
To get the 5 hour interval, one possible workaround is to
schedule the cron job to run every hour
at the start of your script that the cron job runs, add extra logic to check if it should run this hour. For example, you could take the current time, and calculate the hours since epoch. And exit early unless the calculated number is divisible by 5.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I am attempting to run a cron job every minute between 7AM and 12PM the expression I am attempting to use is as follows:
*/1 7-24 * * *
which doesn't appear to run correctly. I am fairly new to writing such expressions, could anyone point me in the right direction for what I am trying to achieve
If you mean every minute between 7:00 and 12:00 (12pm, noon), use this:
* 7-12 * * *
If you want every minute between 7:00 and 24:00 (12am, midnight), use this:
* 7 * * *
Other combinations you can try here: crontab guru
First star already means every minute, so there is no need to manipulate this further.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I want to run cron job every 2 hours In the X minute
Example:
every 2 hours In the 24 minute
00:24
02:24
04:24
etc.
Put your desired minute in the minute column, and then use */2 in the hour column to get it to run every two hours.
24 */2 * * * <your command>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to create a cron job that will run on the every 1st day of the month every minute of this day. I will create it from cpanel.
Any help is appreciated. Thanks
The crontab entry should look like this :
* * 1 * * cmd_to_run
The columns mean
every minute
every hour
1st day of month
every month
any day of week, and then the command.
I'm not sure about cpanel admin
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have a text file containing a specific date and time.
I want to be able to run a script at the time specified in that file.
How would you achieve that?
Create another script that runs in background (sort of a deamon) and checks every second if the current time is matching the time in the file?
Is there another way?
The machine is a linux server , Debian wheezy.
Thanks in advance
Look at the following:
echo "ls -l" | at 07:00
This code line executes "ls -l" at a specific time. This is an example of executing something (a command in my example) at a specific time. "at" is the command you were really looking for. You can read the specifications here:
http://manpages.ubuntu.com/manpages/precise/en/man1/at.1posix.html
http://manpages.ubuntu.com/manpages/xenial/man1/at.1posix.html
The at command exists specifically for this purpose (unlike cron which is intended for scheduling recurring tasks).
at $(cat file) </path/to/script
Cron is good for something that will run periodically, like every Saturday at 4am. There's also anacron, which works around power shutdowns, sleeps, and whatnot. As well as at.
But for a one-off solution, that doesn't require root or anything, you can just use date to compute the seconds-since-epoch of the target time as well as the present time, then use expr to find the difference, and sleep that many seconds.
Usually in Linux you use crontab for this kind of scduled tasks. But you have to specify the time when you "setup the timer" - so if you want it to be configurable in the file itself, you will have to create some mechanism to do that.
But in general, you would use for example:
30 1 * * 5 /path/to/script/script.sh
Would execute the script every Friday at 1:30 (AM)
Here:
30 is minutes
1 is hour
next 2 *'s are day of month and month (in that order) and 5 is weekday
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
This question does not appear to be about programming within the scope defined in the help center.
Improve this question
Is it possible to have two linux users with slight delays on their clocks?
The reason I ask is I have two scripts executed by the cron every minute (one on each user). One script copies a file from the another machine the other loads the data in the file into mysql.
We have been finding the loading of the data misses the first minute 90% of the time. I think this is because it is called exactly the same time as the call to copy the file from the other machine is executed.
If I could delay the user clock whose cron executes the loading script by 5 seconds i think this would solve the problem.
Perhaps there is another way of achieving this? Something easier I am missing. I would like the first script to be called every round minute and the second to be called 5seconds after every round minute.
Add a sleep 5 or sleep 10 to the start of the cron entry.
Probably the best answer to this is to set up xntp so the clocks are in sync. Then, as glglgl suggests, put a sleep at the top of the script you want delayed.