Cron task scheduling and stopping after certain interval
6,640
You have got here a very comprehensive tutorial.
http://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800
In the example you show us, the cron is running every two hours, at minute 51.
For running the script every 20 minutes, you would do
*/20 * * * * /root/backup.sh
Related videos on Youtube
![Manjurul Islam](https://lh5.googleusercontent.com/-mBRk6lvpqVA/AAAAAAAAAAI/AAAAAAAAAJA/YoS7qoUxDVE/photo.jpg?sz=256)
Author by
Manjurul Islam
Updated on September 18, 2022Comments
-
Manjurul Islam almost 2 years
I am managing a server which has multiple cron tasks, one of the crontab entry is like below:
51 */2 * * * /root/backup.sh
can anyone explain me what is happening here, at what time the script is running?
I want to run one script 20 minutes every hour, and another script every 20 minutes interval, how will I accomplish it?
Also, I want to run my third cron for 20 or 30 minutes, then it will stop, will resume again next hour, or every two or three hours, run again for 20 minutes, then stop, can I do this?
-
roaima over 8 yearsAssuming you have the
cron
entry configured to start a new instance every 20 minutes. Do you want each instance to run for a maximum of 20 minutes? Or would you prefer for the job to run to completion, but avoid running another copy of the job while the first is in progress? -
Manjurul Islam over 8 yearsI want to run the cron for 20 minutes, then it will stop. A new instance will run on the next hour or every two hours.
-
roaima over 8 years1.
cron
won't stop your job. You are aware of that, yes? 2. In your question you say you want the job to run every 20 minutes. Here in your comment you say you want it to run every 2 hours. Please decide! -
Manjurul Islam over 8 yearsI want to run the job for 20 minutes every two hours. Like 12am it will for 20 minutes, then again on 2am for another 20 minutes
-
roaima over 8 yearsThen please edit your question to say so. At the moment it clearly says, "I want to run the script every 20 minute[s]".
-
Manjurul Islam over 8 yearsHi, I have edited the descriptions. Thanks for your concern about this community.
-
-
Manjurul Islam over 8 yearsso that mean the cron is running at 00:51, then next it is running at 2:51, then at 4:51 right?
-
Manjurul Islam over 8 yearshow can I make the cron to run for a particular time, then stop, like it will run for 20 minutes, then stop, then will start again on next hour,
-
Rui F Ribeiro over 8 yearsexactly that. Every two hours, same minute.
-
Rui F Ribeiro over 8 yearsPlease read the tutorial, all explained there.
-
roaima over 8 years@ManjurulIslam
cron
does not care about stopping a job, only starting it. If you need this requirement please edit your question to include this detail. -
Manjurul Islam over 8 years@roaima Thanks for the suggestion, I have edited both the title and the contents of my question.