I want to run a script through linux cron which will run after 9 hour.
For example: If current time is 00:34 and I start the cron now, then my shell script should run at 00:34 and then at 09:34 and at 18:34 and so on. For this I have entered the below cron :
34 */9 * * * /path/to/script/foo.sh
But this is not working as expected. So, Any help would be helpful.
I don't think its possible to do that for every 9 hour window. The way you have currently scheduled it, it will run at 00:34, 09:34, 18:34 every day and not in 00:34, 09:34, 18:34, 3:34, 12:34 fashion.
You should instead run it every 3 hours (24 hours/day, 3 is the highest common factor between 24 and 9), using an interim file for storing whether it is the first, second or third 3-hour window of the 9 hours. Based on this value, run the task whenever its the first such window.
Related
How to write a cron which run only on any hour and half (xx:30) ?
For example it would run only at 00:30, 01:30, 02:30, on so on until 23:30.
The first field in a crontab entry is the minutes. You want your job to run whenever the "minutes" part of the current time equals 30, so you need a 30 in the first field. You want it to run at such a time regardless of what the hours, days, or months are, so you put * in the remaining fields.
30 * * * * /my/job
I want to create a cron expression which will run the scheduler every 2.5 min of every hour. e.g. 2.5min, 5.0min, 7.5min, 10.0min etc. of every hour.
I am using Spring to create the scheduler. I tried various combination but nothing worked. One of them is as below but it is not working.
#Scheduled(cron = "*/30 */2 * * * *")
Thanks in advance.
That should works for you
0 0/5 0 ? * * *
30 2/5 0 ? * * *
At second :00, every 5 minutes starting at minute :00, at 00am, of every day
At second :30, every 5 minutes starting at minute :02, at 00am, of every day
You are right in this case you need to schedule your task twice using expression like on example.
There is a danger of becoming fixated on the 30 seconds. My problem was that I needed to check 18000 records for updates every month ~ 1 record every 2.5 minutes. I spent too much time trying techniques to run a job at exactly 02:32:30 before I realised that accuracy was not important.
In my situation, I realised I could execute every 2 minutes, updating my full database every 25 days instead of every 31 days.
Alternatively, I could have had 2 cron jobs running every 5 minutes. First, a 2-minute gap, followed by a 3-minute gap.
02:30 02:32 02:35 02:37 02:40 02:42 02:45 02:47
My point is that when the cron job is live, it runs unseen. Obviously, everyone has their own specific problem, but before introducing complexity, consider if it is necessary. As long as the job executes, does it really matter the exact time it ran?
I have a case in which I'm migrating some tasks from Windows to a platform and we are using cron expressions to replace the Windows Scheduler.
Today we have something in Windows like At 10:20 AM every weekday, every 10 minutes for 9 hours. I'm trying to replace it with chron but I couldn't achieve it so far.
The closest I got is 0 20/10 10-19 * * MON-FRI. The thing is on this cron, it won't execute at 11:00, 12:00 and so on. We have a specific case in which we don't want it to execute at 10:00 AM.
The only option I found is to execute at 10:00AM and put some condition to validate it. Is it possible to achieve this result with only chron?
Thanks!
You can do it with cron, but you'll need to break it up into two schedules.
20/10 10 * * MON-FRI
and
*/10 11-19 * * MON-FRI
Btw, if this is cron on unix, there is no field for seconds.
I need to execute a cronjob to run once for 7 days alone.I have tried like this:
0 0 * * 0-6 myscript.sh
It gets run for once a day and running every day of the week since i gave as 0-6.
But i need to run a job for one week alone not followed by multiple days.I donot want to mention the date of the month,since i need randomly.
(or)
Is it possible through "at" command if it is not through "cron"???
How can i set job to run for 7 days alone guys????
Thanks
For example, if I have a cron job that I want to run every 9 hours:
0 */9 * * * my_script
The job is executed at 00:00, 9:00, and 18:00; and then the same hours the next day.
What I want is for the job to execute at 00:00, 9:00, 18:00; then 03:00, 12:00, 21:00 the next day -- a true "every 9 hours".
Is there any way make cron job run EVERY 9 hours?
Specifying */9 means that the job runs every 9 hours starting at 00:00. It starts again at 00:00 every day.
There is no syntax in cron to run a job every 9 hours.
What you can do is run a job every 3 hours, and have the command itself examine the current time and only execute 1 time out of 3. Or it can run every hour and execute one time out of every 9. Don't assume that the current time will be exact; it might run a few seconds after the hour.