How to activate a process every 15 minutes in Centos

Posted on 2011-05-11
Medium Priority
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

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

Assisted Solution

for_yan earned 164 total points
ID: 35740067

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

ID: 35740131
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.
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

LVL 38

Accepted Solution

wesly_chen earned 168 total points
ID: 35740349
> 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/myscript.sh

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/myscript.sh

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

Expert Comment

ID: 35742477
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

Assisted Solution

eager earned 168 total points
ID: 35748140
Take a look at inotify to start a program when files are added to a directory:

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Fine Tune your automatic Updates for Ubuntu / Debian
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 video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 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