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
285 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
ID: 20410286
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
ID: 20412889
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
ID: 20415169
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
ID: 20426161
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
ID: 20439952
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
ID: 20440062
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:CRISTIANO_CORRADI
ID: 20440066
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
ID: 20440069
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
ID: 20440258
If you kill stomis.exe or startstomis, the calling script will detect a non-zero exit status.
0
 

Author Comment

by:CRISTIANO_CORRADI
ID: 20440330
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
ID: 20442999
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
ID: 20444555
>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
ID: 31412807
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

919 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

18 Experts available now in Live!

Get 1:1 Help Now