Solved

How to execute 16 programs 5 days a week without overlapping and checking the correct end of every execution.

Posted on 2007-12-05
13
283 Views
Last Modified: 2010-04-21
Hello!

Every week (Wed-Thu-Fri-Sat-Sun), excluding Monday and Tuesday, I have to run the following 16 processed for at least ONE time.  

Every process has a random duration from 3 to 5 hours, so I can't use crontab, because the process overlapping is NOT ALLOWED.  

If I don't know when a process ends its execution, I can't schedule it in crontab file because this can't grant the absence of process overlapping.  

Please note that "PER", "AM" and "010" are PARAMETERS of the unique executable file called stomis.exe, stored in $HOME/sistema/exe directory.  

I also NEED TO CHECK the correct end of execution of every stomis process: in fact, it's possible that a user kills a stomis program (in order to free the cpu in critical situations), this means that the related command has to be relaunched because in the last execution it hasn't termined with SUCCESS.

This is the list of the commands that now are in crontab: at present, from time to time, I decomment one row, and launch one single command, waiting for the end of the execution.  Then, I decomment one other row, wait for the process to run, wait the end, and so on.  I always do it manually.

$HOME/sistema/startscript/startStomis PER AM  010
$HOME/sistema/startscript/startStomis PER ER  010
$HOME/sistema/startscript/startStomis PER ER  010
$HOME/sistema/startscript/startStomis PER SA  010
$HOME/sistema/startscript/startStomis PER TO  010
$HOME/sistema/startscript/startStomis PER CA  010
$HOME/sistema/startscript/startStomis PER FV  010
$HOME/sistema/startscript/startStomis PER MU  010
$HOME/sistema/startscript/startStomis PER PU  010
$HOME/sistema/startscript/startStomis PER SI  010
$HOME/sistema/startscript/startStomis PER TA  010
$HOME/sistema/startscript/startStomis PER VE  010
$HOME/sistema/startscript/startStomis PER CB  010
$HOME/sistema/startscript/startStomis PER LA  010
$HOME/sistema/startscript/startStomis PER LO  010
$HOME/sistema/startscript/startStomis PER LI  010
$HOME/sistema/startscript/startStomis PER PV  010

I need a program that schedules the launch of these commands, checking the correct execution, granting no overlap between processes, and granting that every process has been executed at lease one time a week, in the available days (no Monday, no Tuesday).  

Please note that, in this problem, stomis.exe is a BLACK BOX, so you can't decompile it or recompiling: YOU HAVEN'T the source code.

Thank you in advance for your kind cooperation.
0
Comment
Question by:CRISTIANO_CORRADI
  • 7
  • 4
  • 2
13 Comments
 

Author Comment

by:CRISTIANO_CORRADI
Comment Utility
This is the content of the startStomis file:

[61] % more startStomis
#!/bin/csh

#THE PARAMETER $1 CAN BE (PER RT NAZ)
#THE PARAMETER $2 CAN BE (AM CA CB ER FV LA LI LO MU PU PV SA SI TA TO VE)
#THE PARAMETER $3 is a string of three 0/1 characters.
#The 1st character is related to delete old records        (1=YES/0=NO)
#The 2nd character is related to populate aggregate data   (1=YES/0=NO)
#The 3rd character is related to populate statistical info (1=YES/0=NO)
# If I want only delete old records, I use 100.
# If I want to populate aggregate data, I use 010.
# If I want to delete old record AND to populate aggregate date, I use 110.
# ... and so on!

#THE PARAMETER $4 is a string DDMMYYYY which represents a START DATE for the procedure
unalias cd

setenv NOME_PROCESSO stomis
setenv NOME_FILE _"$1"_"$2"_
setenv LOG_LEVEL 3


$HOME/sistema/exe/stomis.exe "$1" "$2" "$3" "$4"
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 250 total points
Comment Utility
How should you determine if the program terminated with SUCCESS?  Are you using it's return value, or some output?
When it terminates without SUCCESS and needs to be restart, should it be restarted right away, or after some time?

Here is a sample perl program.  It uses the return value to determine SUCCESS, and will wait 60 seconds before trying again.

You could put this in the cron, and it will execute all of your commands one at a time.
my $ProgramName = '$ENV{HOME}/sistema/startscript/startStomis';

my @Params = ('PER AM  010',

              'PER ER  010',

              'PER ER  010',

              'PER SA  010',

              'PER TO  010',

              'PER CA  010',

              'PER FV  010',

              'PER MU  010',

              'PER PU  010',

              'PER SI  010',

              'PER TA  010',

              'PER VE  010',

              'PER CB  010',

              'PER LA  010',

              'PER LO  010',

              'PER LI  010',

              'PER PV  010',

              );
 

foreach (@Params) {

	my $ret = -1;

	do {

		$ret = system$ProgramName . " " . $_);

		if($ret != 0) {

			if ($? == -1) {

				print "failed to execute: $!\n";

    		}

    		elsif ($? & 127) {

				printf "child died with signal %d, %s coredump\n",

				    ($? & 127),  ($? & 128) ? 'with' : 'without';

			}

			else {

				printf "child exited with value %d\n", $? >> 8;

			}

			print "Trying again...\n";

		}

	} while ($ret != 0);

}

Open in new window

0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 250 total points
Comment Utility
What I'd do is create the below script and schedule it via crontab for Wed-Sun.  

What it does, is to invoke each of the jobs and if any of them fail, it keeps invoking it until it succeeds.
#!/bin/sh

launch()

{

  while true

  do

    $HOME/sistema/startscript/startStomis $1 $2

    [ $? -eq 0 ] && return

  done

}
 

launch AM  010

launch ER  010

launch ER  010

launch SA  010

launch TO  010

launch CA  010

launch FV  010

launch MU  010

launch PU  010

launch SI  010

launch TA  010

launch VE  010

launch CB  010

Open in new window

0
 

Author Comment

by:CRISTIANO_CORRADI
Comment Utility
But your programs have to run always in background....  
I think to a solution via crontab, such this:

35 10 * * * $HOME/sistema/startscript/startStomis PER AM  010
50 12 * * * $HOME/sistema/startscript/startStomis PER ER  010
35 09 * * * $HOME/sistema/startscript/startStomis PER SA  010
50 11 * * * $HOME/sistema/startscript/startStomis PER TO  010
35 16 * * * $HOME/sistema/startscript/startStomis PER CA  010
40 10 * * * $HOME/sistema/startscript/startStomis PER FV  010
05 17 * * * $HOME/sistema/startscript/startStomis PER MU  010
45 12 * * * $HOME/sistema/startscript/startStomis PER PU  010
40 17 * * * $HOME/sistema/startscript/startStomis PER SI  010
15 14 * * * $HOME/sistema/startscript/startStomis PER TA  010
50 14 * * * $HOME/sistema/startscript/startStomis PER VE  010
15 16 * * * $HOME/sistema/startscript/startStomis PER CB  010
20 14 * * * $HOME/sistema/startscript/startStomis PER LA  010
20 14 * * * $HOME/sistema/startscript/startStomis PER LO  010
00 10 * * * $HOME/sistema/startscript/startStomis PER LI  010
20 10 * * * $HOME/sistema/startscript/startStomis PER PV  010

But I have to GRANT the ABSENCE of OVERLAPPING between startStomis processes.

How can I modify the startStomis script in order to avoid the overlap between processes?  At present, we have the following code for startStomis:

#!/bin/csh
#THE PARAMETER $1 CAN BE (PER RT NAZ)
#THE PARAMETER $2 CAN BE (AM CA CB ER FV LA LI LO MU PU PV SA SI TA TO VE)
#THE PARAMETER $3 is a string of three 0/1 characters.
#The 1st character is related to delete old records        (1=YES/0=NO)
#The 2nd character is related to populate aggregate data   (1=YES/0=NO)
#The 3rd character is related to populate statistical info (1=YES/0=NO)
# If I want only delete old records, I use 100.
# If I want to populate aggregate data, I use 010.
# If I want to delete old record AND to populate aggregate date, I use 110.
# ... and so on!
#THE PARAMETER $4 is a string DDMMYYYY which represents a START DATE for the procedure
unalias cd
setenv NOME_PROCESSO stomis
setenv NOME_FILE _"$1"_"$2"_
setenv LOG_LEVEL 3
$HOME/sistema/exe/stomis.exe "$1" "$2" "$3" "$4"
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 250 total points
Comment Utility
CRISTIANO, are you changing your requirements now?  

According to your original specifications, my script should do exactly what you require.  Please tell me why you think it doesn't meet your requirements.
0
 

Author Comment

by:CRISTIANO_CORRADI
Comment Utility
startStomis invokes the executable binary file stomis in the following row:

$HOME/sistema/exe/stomis.exe "$1" "$2" "$3" "$4"

What happens if I kill stomis.exe program?  What is the result of the control:     [ $? -eq 0 ] && return

By killing the stomis.exe program, does your program consider startStomis ended with success or with failure?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:CRISTIANO_CORRADI
Comment Utility
Of course, if I call stomis.exe program, the result of startStomis has to be failure: does your program do so?
0
 

Author Comment

by:CRISTIANO_CORRADI
Comment Utility
excuse me, I wanted to write "if I kill stomis.exe program" instead of "if I call stomis.exe program".
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 250 total points
Comment Utility
If you kill stomis.exe or startstomis, the calling script will detect a non-zero exit status.
0
 

Author Comment

by:CRISTIANO_CORRADI
Comment Utility
A non zero exit status means failure?  This means that the loop will try again to run the same AM 010, for example?
0
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 250 total points
Comment Utility
In both my and TinTins code, you would only call the one script from the cron - that script would then call the startStomis, making sure only 1 was active at a time, and trying again if it failed.
Change your crontab to only call the new script.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 250 total points
Comment Utility
>A non zero exit status means failure?  This means that the loop will try again to run the same AM 010, for example?

Correct.  Which is what you requested in your original specifications.
0
 

Author Closing Comment

by:CRISTIANO_CORRADI
Comment Utility
Thanks!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

771 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

14 Experts available now in Live!

Get 1:1 Help Now