How to activate a process every 15 minutes in Centos

Posted on 2011-05-11
Last Modified: 2012-05-11

I have two java programs each of which does some mysql queries or check local file systems in CentOS. I want to have one program automatically run every 15 minutes, and if some conditions met, the program will write a few files in local directories. The other program needs to run whenever the local directories have new files available for processing.

How can I write some scripts that achieve the goals? Does it involve multi-threads?

Question by:wsyy
    LVL 47

    Expert Comment

    You can do it with cron job with 4 lines in crontabfile
    LVL 47

    Assisted Solution


    This is the crontab:
    Use your command instead of copyPDF
    30 * * * 0-6 $HOME/cron/copyPDFs
    00 * * * 0-6 $HOME/cron/copyPDFs
    15 * * * 0-6 $HOME/cron/copyPDFs
    45 * * * 0-6 $HOME/cron/copyPDFs

    Open in new window

    after you create crontab.file  to start it
    should be:

    crontab crontab.file

    I am using it not on Linux but should work
    the same on any Unix

    LVL 47

    Expert Comment

    Another part of it is to check when new files arrive and start other processes
    For that you can write java program and make it sleep and at regular
    intervals check for the presencce of the file and start the required process.

    On the other hand if these every 15 min running prigrams generate files - it is probably
    better to start the processing files from these very programs, or if other prtograms should be running on another
    computer you may just schedule them the same way with cron job say five minutes later -
    and they would check if there are new files, they would go ahead, otherwise would exit.

    In other words there are lots of pissibilities, all depends on your specific envirionment and habits.
    LVL 38

    Accepted Solution

    > run every 15 minutes, and if some conditions met, the program will write a few files in local directories
    > The other program needs to run whenever the local directories have new files available for processing.

    1. Combine these two task into one script
    -- /home/<user>/script/

    export PATH=/usr/bin:/bin:/usr/local/bin # add java path here if you use java

    if [ <condition> ]
       <action to write a few files in local directories>
       <action to process those files>

    2. Make it executable
    chmod +x /home/<user>/script/

    3. Set up a cron job for every 15 minutes
    crontab -e
    */15 * * * * /home/<user>/script/ > /dev/null 2>&1
    LVL 92

    Expert Comment

    what do you need the script to do exactly. From what you have said yopu simply need to run each of your java apps periodically
    the first would query database and create file
    the second would process any files in the directory
    nice and simple
    LVL 8

    Assisted Solution

    Take a look at inotify to start a program when files are added to a directory:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now