• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

How to activate a process every 15 minutes in Centos

Hi,

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?

Thanks!
0
wsyy
Asked:
wsyy
3 Solutions
 
for_yanCommented:
You can do it with cron job with 4 lines in crontabfile
0
 
for_yanCommented:


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


0
 
for_yanCommented:
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.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
wesly_chenCommented:
> 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
#!/bin/bash

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

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

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
0
 
objectsCommented:
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
0
 
eagerCommented:
Take a look at inotify to start a program when files are added to a directory:
http://linux.die.net/man/7/inotify
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now