1

I've inherited a medium sized project in which the main (batch) program is fed work through a large set of shell scripts that do a lot of process control (waiting for process to complete, sleeping, checking for conditions, etc) [ and reprocessed through perl scripts ]

Are there other examples of process control by shell scripts ? I would like to see what other people have done as a comparison. (as i'm not really fond of the 6,668 line shell script)

It may lead to that the current program works and doesn't need to be messed with or for maintenance reasons - it's too cumbersome and doing it another way will be easier to maintain, but I need other examples.

To reduce the "generality" of the question here's an example of what I'm looking for: procsup

jim
  • 1,502
  • 12
  • 23

3 Answers3

0

This is quite general question, and therefore giving specific answers may be a little bit difficult. (And you wont be happy with 5000 lines long example.) Most probably architecture of your application is faulty, and requires rather complete rework.

As you probably already know, process control with bash is pretty simple:

./test_script.sh &
test_script_pid=$!
wait $test_script_pid # waits until it's done
./test_script2.sh
echo $? # Prints return code of previous command

You can do same things with for example Python subprocess (or with Perl, obviously). If you have complex architecture with large number of different programs, then process is obviously non-trivial.

Olli
  • 1,231
  • 15
  • 31
  • If you run the job in background and then wait for it to finish, why did you bother with backgrounding it? – Jonathan Leffler Feb 23 '11 at 17:47
  • @Jonathan: you can do other things when it's running on background, for example start multiple jobs at the same time and then wait for each. That listing was meant to be only example of syntax. – Olli Feb 23 '11 at 18:03
  • @Jonathan: Another great reason to do this is so you can insulate yourself from hung commands etc - you can start, for example, a timer and kill the background job if it doesn't finish quickly enough. – ostergaard Oct 18 '12 at 09:33
0

Inquisitor project relies on process control from shell scripts extensively. You might want to see it's directory with main function set or directory with tests (i.e. slave processes) that it runs.

GreyCat
  • 16,622
  • 18
  • 74
  • 112
0

That is an awfully bug shell script. Have you considered refactoring it?

From the sound of it, there may be a lot of instances where you could replace several lines of code with a call to a shell function. If you can simplify the code in this way, then it will be easier to see where there are errors in the logic.

I've used this tactic successfully with a humongous PERL script and it turned out to have some serious logic errors and to be a security risk because it had embedded passwords that were obfuscated in an easily reversible way. The passwords that were exposed could have been used by persons unknown (well, a disgruntled employee) to shut down an entire global network.

Some managers were leaning towards making a security exception because this script was so important, but when the logic error was explained and it was clear that this script was providing incorrect data, it was decided that no data was better than dirty data. The guy who wrote that script taught himself programming with a PERL book and the writing of the script.

Michael Dillon
  • 31,973
  • 6
  • 70
  • 106
  • Yes, I'm considering of refactoring it which prompted this question; more of is there an existing library that does this that I can use vs building another house of cards OR leave it. Since it's critical production code I'm starting to lean towards "don't mess with it" – jim Feb 25 '11 at 15:00