Run cronjob for missing time periods - cron

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.

Related

Is there a way to run a program and kill every 20 seconds in linux?

I have a program that i need to collect 300 pieces of data from, but to manually do the collecting i have to run the program on my ubuntu virtual machine and record the data on excel. It takes a long time to do this whole process. I was wondering if there was a command in linux that i could use to call commands make and to kill me program.
I search watch and tried it but it doesnt work for me:
watch -n 20 make play
where make play runs my program
Yet this doesnt fo everything i want to do. I want to do this every 20 seconds so i have enough time to write my data to my excel file
1. make play (run my program so it prints what i need to record)
2. kill my program
Is there a command for this?
I think you should rethink what you are doing - I can't think of a setting where running and killing a program every 20 seconds makes any sense.
That being said, the standard way to run programs periodically in linux is a cron job. Cron has a 1 minute minimum though, so you would have to write a script that starts 3 instances of your program with 20 second delay, and run this script with cron every minute. You can combine this with the timeout utility, which will kill your program if it is still running after a given time. A quick google search should provide you with further details.
I think you Could use crontab, man crontab to get the manual of crontab. However, you may not be able to run and kill every 20s, at least every 1 min. Hope It could help.

Calling a specific method on a certain time

I am currently working on a web application and I want to schedule a method that runs every day at 6 AM. Basically, if the clock ticks at 6 AM, this method will run. I have seen some answers on the Internet but none of these are scheduled at a fixed time of the day but rather timed after the app is ran.
I also have an alternative solution which is to check every minute if the time is 6 AM, and if so, I'll run the code. But is there other better answer than this?
Thank you!
On the server side, you could do it with a cron job.
On Linux follow these steps:
crontab -e
Here's an example of how to make a request to the google.com at 6AM (UTC)
# Each day at 6th hour (6 AM depending on your time zone settings, or UTC)
0 6 * * * curl -I http://google.com
:wq # save changes and quit
:q # to quit
:q! # to quit without saving changes
See more about Cron here. Or use a visual crontab entry creator if that is helpful. If you need a solution for Windows machine, you could also use a Windows scheduler to trigger events similar to cron.
Cron job would be a good way of doing it. However, for some reason if you can not schedule a cron job and need your own scheduler and your environment is Java based then you could use the Quartz Scheduler. It is a java based job scheduler like cron. It's usage is pretty simple.

Running cron less then one minute- laravel

I wanna ask if is there any way to set cron in laravel less then one minute. right now execute script in while true loop is inconsiderable. I'm talking about LINUX system.
You can not execute cron jobs with less than one minute interval.
You can check alternate solutions on
https://serverfault.com/questions/49082/can-i-run-a-cron-job-more-frequently-than-every-minute

Run Cron Job in Background on Linux/Apache

I have a cron job I need to run every 7 days to aggregate up a bunch of data using a php script. The process is pretty CPU intensive and can take a decent amount of time. Despite setting it to run at 4 am (when we get the least amount of traffic) users are starting to notice some down time when the script runs. Is there a way to run this in the background only when the CPU is not being used or has an open thread?
Thanks!
In the cron job line, you can wrap the php command line with either the 'nice', 'chrt' or 'loadwatch' programs.

Advanced Scheduled Process/Task Manager - Linux

Need some advice, I'm after a decent process/task manager for Ubuntu.
Basically I have a few scripts/programs which I want to run as long running processes, but I want to shut them down at various periods (say over the weekend or every day for a few hours). During the time that the process needs to be up and crashes, I would like it so that the task scheduler will automatically restart the process.
SO for example, I want to run program X between 9:00-17:00 every day. If the process is still running it should be killed at 17:00. If the process crashes between 9AM and 5PM then the process should be automatically restarted.
Are there any easy to use tools which can do this? I would like to avoid having to manage PID files and having cron jobs which do the start and stop...
Any thing anyone recommends? Any advice appreciated!
Cheers.
I do not know if a tool exists for this, but except if you have many interactive tasks, it really does not a that big issue to manage for a few jobs :
1) You can start your cronjobs whenever you like thanks to the crontab,
2) You can insert a "commit suicide" within these scripts under a time condition for example.
# your script doing things
# Then it commit suicide
if [ your_condition ];then
kill $$
fi
Please note that if you want to allow users login only at certain periods of time, then it's a different question.

Resources