scheduled task on centos server - linux

I tried now + time on centos, but it didnt work perfectly for me.
I want my centos server to run a script within 10 mins exactly after 5 days whenever the server is started, either it is started # 1pm or 5pm or 12 am or on the 7th day or 13th day i.e. recurring on server start after 5 days is over.
Can any one help please

Maybe I didn't understand your question... but did you already try with at command?
I mean something like this:
at now + 5 days < /path/to/yourscript.sh
Where yourscript.sh should have a loop waiting 10 minutes between each operation.

Related

Cron Scheduler use case

I am stuck and seek your help for my requirement , where I need to run a job everyday except on Sunday mornings from 05:30 AM to 08:30 AM.
I have searched and could not see the solution for my problem, could you be able to help me out to get the correct Cron Expression. I have also tried it using http://www.cronmaker.com/
i think the easiest solution in cron is:
start your program without any limit
stop your code at 5:30 AM on sundays
30 5 * * 7 stop_code
start your code at 8:30 Am on sundays
30 8 * * 7 start_code_again
Thank you all for your response.
I have used a CronRoutePolicy with respect to Camel as we were using Camel.
In the route policy i could define Start time , Suspend Time and Resume Time.
I have deployed it but some how quartz has not started the job. Figuring out the issue now.

Do Cronjobs remember last runtime after reboot?

Consider the following scenario:
Let's say I have a cronjob running every 3 hours (0 */3 * * *).
The job just ran 2 minutes ago.
If I were to reboot my computer right after it runs, will the cronjob remember that it just ran ~2 minutes ago, or will it run directly after it boots?
Neither.
It doesn't need to remember that it just ran. The job runs at 0:00 03:00, 06:00, etc. If the system isn't up at the scheduled time, the job doesn't run.
If the job ran at 03:00 and you reboot at 03:02, the job won't run again until 06:00.
(If you want jobs to run if they couldn't run before because the system was down, see anacron.)

Cron Job Issue with day of Month

I have a cron job set to run a script once a day at 3am.
0 3 * * * /home/path/script.pl
It's been running without any problems since April 11th. Last weekend though, on Saturday the 3rd of May, the script was called once a minute for 24 hours. (1441 times in total) Then afterwards, on the 4th and 5th, it went back to only being called once a day at 3:00 again.
Does anyone have any ideas as to why this happened? I was wondering if there was an error in my crontab, since I have a 3 in it, and it was the 3rd of May that it happened. Since I only started running the cron since the 11th of April, I have no idea if it's something that will happen once a month on the 3rd, or if it was a one time thing unrelated at all.
I looked around and didn't find anything related, so I though I'd just ask while I continued to tried to find out what happened. I currently changed the cron to make it run at 6am instead to see if I'd end up with the same thing again tomorrow.
0 6 * * * /home/path/script.pl
EDIT
Everything was working fine, but then again on the 3rd of June, the same thing happened again. Could this be related to a cron problem or could it be something else entirely?
The problem was finally solved. There was a second cron being executed by root that was incorrectly written, which was making the script be called once a minute on the 3rd of the month instead of once a day at 3am.
The cron did not show up with the other cron jobs, and only by using the following command
did the cron job actually appear.
grep script /var/spool/cron/crontabs/*
I still don't understand but it's working correctly now.

Run cronjob for missing time periods

I Have crontab set up (on my local MacOSX system) to run a job on a per hourly basis. It runs fine. I am not sure if it is possible, but is there a way that I can run the job for 'missing' hours (in case my computer sleeps or I shut it down)?
For example if cronjob ran fine for hours (1-13) before I shut down the system. I start up the system again after, lets say 2 hours. Is there a way to tell cron to run the job for missing hours (14,15) too before executing hour 16?
The cronjob currently running fills up some data in my local MySQL DB with hour information in one of the columns. Any tips, tricks or libraries will be helpful.
Thanks.
Maybe have a look at anacron for Mac that can catch up jobs missed while your Mac was sleeping the next time it wakes up. See here.

Repartition of cron

(I apologize in advance for bad formulation of my problem, please consider english is not my first language).
I have several processes (crons) and I want to "optimize" the schedule when to launch them.
For example, cron c1 starts every 3 minutes, cron c1 starts every 7 minutes and cron c3 starts every 18 minutes. Assume they last only a few seconds before stopping.
The unit of time here is 1 minute.
Now, what I want is that these crons are distributed so that we don't have a moment where many of them start and then long time interval with no cron at all. For example, if c1 and c3 both start at time 0, then they will start again together every 18 minutes. It would be better to start cron c1 at time 0 and then c3 at time 1, so that they are never launched together.
So the idea is, given a list of crons with periodicity, to plan a schedule, so that there is as much time between each cron as possible and as few as possible moments when two crons start together.
Are there some well-known algorithms about such problems?
The real-life application of this problem is: ~ 200 crons. Some of them are launched every 5 or ~10 or ~30 minutes and last very short (few seconds), some (~20 - 25) are launched every 2 hours and last a few minutes. So the idea is also that the big crons are not launched at the same time.
I am a mathematician myself and not a computer scientist, so I asked this question on https://math.stackexchange.com/, since I consider this being a "nice" question for mathematicians too.
I think you should consider the ressources used by each of your crons and then schedule your jobs from that.
I don't think there is a particular algorithm for that.

Resources