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
Share:
6,640

Related videos on Youtube

Manjurul Islam
Author by

Manjurul Islam

Updated on September 18, 2022

Comments

  • Manjurul Islam
    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
      roaima over 8 years
      Assuming 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
      Manjurul Islam over 8 years
      I 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
      roaima over 8 years
      1. 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
      Manjurul Islam over 8 years
      I 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
      roaima over 8 years
      Then 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
      Manjurul Islam over 8 years
      Hi, I have edited the descriptions. Thanks for your concern about this community.
  • Manjurul Islam
    Manjurul Islam over 8 years
    so that mean the cron is running at 00:51, then next it is running at 2:51, then at 4:51 right?
  • Manjurul Islam
    Manjurul Islam over 8 years
    how 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
    Rui F Ribeiro over 8 years
    exactly that. Every two hours, same minute.
  • Rui F Ribeiro
    Rui F Ribeiro over 8 years
    Please read the tutorial, all explained there.
  • roaima
    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
    Manjurul Islam over 8 years
    @roaima Thanks for the suggestion, I have edited both the title and the contents of my question.