I was trying to run cron jobs , but I wanted make next cron job dependent on previous one (Cascade them) . So the second cron job would be triggered only if first cron job ( which runs java code) was successful and not otherwise. My cron entries are as follows:
As you can see first cron job would run @ 3:45 am and execute cron.java with "parameter1" passed as argument. What I want is to run 2nd cron job @ 3:50 am only if Java process created by 3:45 am cron has successfully executed and that (3:45 AM) JVM process has terminated successfully.
If Java process created by 3:45 am cron hasn't terminated ( still running ) then 3:50 cron should not run ( be in pending mode and monitor status of 3:45 am Java process) and as soon as 3:45 am Java process is complete , it should trigger 3:50 am process , which was in pending mode.
This will continue for each sub sequent processes...meaning 3:52 AM process will wait on 3:50 AM process .... and 3:55 AM process will wait on 3:52 AM process ...so on and so forth.
I am sure some of you experts have run into this and have different solutions to resolving it. Would appreciate if you could provide pointers on how to proceed from here.
Hi,
I think You should have a look at a concept known as PID-files, ie a flag in the form of a file in a known location that indicates whether a process is running.
When a process starts, it writes its status to a file, maybe a PID or for example the text "running" and upon exit it writes "fail" or "success".
Any subsequent processes will check the known location for info and take action accordingly.
Unless You have very strict requirements on process control I find the file system very useful for simple tasks. You may of course run into problems with different types of erros, such as Your app not being able to return an exit code, handling erros that emanate from cron, etc.
As others have stated, use a file to tag to see if the process completed or is still running. If you can modify your java code, you can have the java code write the little status files. If that's not possible, just wrap it all up in a shell script. Something like;
For the 1st java process
And for the 2nd process, something like;
So the 1st script creates a /var/tmp/process-status.txt file, with the word "running" in it. It then launches your java process. When the java process exits, it writes "complete" into the file.
The 2nd script will only start the 2nd java process if it can find the word "complete" in the /var/tmp/process-status.txt file. If it finds the word "complete" in the file, it will start up the 2nd java process. It'll do this check 10 times, waiting 60 seconds between checks. If all 10 checks fail, then it'll spit out an error. If cron is configured properly, cron will automatically generate an email to root@locahost with any output. You could probably run "mailx" or something to generate a nicer email message or something.
Note I didn't test any of this, so there are probably quite a few bugs, or better ways to do it (e.g. inside a for loop perhaps). I'm sure other posters will point those out. But it should give you a good idea on how to do it.
Don't see why you have to have separate cron jobs! Why not just have a single script that joins all of the others together with their interdependencies?
There are two jobs in Solaris , Cron and at jobs..
I know how to disable or enable cron jobs.
How can I enable at jobs and disable it.
Kindly help.
Rj (2 Replies)
Hi,
please help on this am trying to exec the below mentioned cron jobs
but its getting failed fro the past two days
###but when am trying to execte the cron by the times
23,29 18 * * * /export/home/inrvgo/thelak/China.sh
its getting exec properly
please help on this
#... (8 Replies)
Hi,
I am a Linux administrator (newbie) in my company. The distro being used in the servers here is Centos 5.3
Just need to know, as a Linux administrator is it better for me to use /etc/crontab to set my cron jobs. I do not want to use the crontab -e to schedule my cron jobs.
That means... (1 Reply)
Hi,
We have a group of hosts using which the cron jobs are submitted...
Few days ago i had submitted a cron job in of these hosts, but unfortunately forgot the host name :(
Can anyone please help me out in finding this host name from which the cron s submitting the job, i dont want the... (2 Replies)
how to Put a cron entry which should be same script triggered on every Saturday and 1st of every month at 01.00 GMT.
0 2 1 * 6 --( At 2.00 GMT every sat & on 1st of every month)
the above syntax is correct?
Thanks (1 Reply)
I'm trying to run cron jobs to start any inhibited processes after a system reboot.
I can schedule th cron, but i'm confused as to how to incorporated the reboot, since reboot is scheduled at different times, once every month.
How can I write this to start every 15 min after after a reboot
... (2 Replies)
I need to monitor my cron jobs with another unix machine since occasionally the cron will go down on the main server but there are no errors. Can anyone help with a script to write to use the cron on the back up machine to monitor the main server?
I am using SCO and the cron jobs have been... (3 Replies)
Hi,
I am a total newbie to all things Unix. I've worked out I need to set up something that will allow me to automatically backup a DB for me, the DB is for a foum system I run.
Now, I've only found out I need to use telnet for this, and worked out hwo to log into telnet today. From here... (4 Replies)