control over shell script | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

control over shell script

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-19-2007
JLJ JLJ is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 22 January 2007, 1:49 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
control over shell script

Hi..
I have a perl program that uses "system" to execute a shell script called startengine. The script "startengine" itself calls a lot of other smaller scripts to setup the engine etc. It finally has to execute ./engine which is another shell script which is long and takes a long time to complete processing.

The "startengine" script looks like this

#!/bin/bash
echo In shell script............
/usr/agjy/bin/cleartool setview $1 <<END

cd /vobs/eng/work
. ./setup host-dbg gw

cd \$ENG_TARGET_ROOT/home/bin
pwd

/home/agjy/bin/stopAll
/home/agjy/bin/cleanup

./engine 2>&1 |tee $2


My problem is that the system call returns back to perl script without waiting for ./engine to finish processing..
I have tried sleep in the perl script which works only sometimes depending on machine speed. Another problem is that ./engine is a waiting process- ie if it runs correctly it should say "waiting for connection.. " and wait for input. the output of ./engine is written into the logfile ($2). The perl script then parses that
logfile looking for the "waiting for connection" string and proceeds to send input to the engine or shut it down depending on if string was matched or not.

I need something that will make sure ./engine is completely processed before control returns to perl script..
I hope i have made the problem clear and would really appreciate any help with this..

Thanks,
JLJ
Sponsored Links
    #2  
Old 01-22-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Advisor  
Full Time Dad
 
Join Date: Sep 2006
Last Activity: 4 April 2014, 3:58 AM EDT
Location: Rossem, Tazenda
Posts: 1,211
Thanks: 6
Thanked 17 Times in 16 Posts
use the Proc::Simple package to launch your shell script. Then you can keep watching the status of that launched process, know when it is finished, and also kill it if required.
Sponsored Links
    #3  
Old 01-22-2007
JLJ JLJ is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 22 January 2007, 1:49 AM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thank You Yogesh for replying.. I will try that but do you know of any other way without using packages?
    #4  
Old 01-22-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Advisor  
Full Time Dad
 
Join Date: Sep 2006
Last Activity: 4 April 2014, 3:58 AM EDT
Location: Rossem, Tazenda
Posts: 1,211
Thanks: 6
Thanked 17 Times in 16 Posts
The crude method is to modify the .engine script to write a line in the log "engine process completed" or something similar. Then in the Perl script, keep iterating in a loop to watch the log and when this line is found, continue further execution. But this is an unreliable method and should be avoided.

Use Perl's Thread model if you don't want to use external packages. This will help you: http://www.unix.org.ua/orelly/perl/prog3/ch17_02.htm This is the 17th chapter of the Camel Book that I am referring.

But I recommend that you use the Proc::Simple package in this case, it will make your life simple.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to continue shell script execution process without control going to pompt? vadlamudy Shell Programming and Scripting 5 04-12-2012 05:43 PM
Version Control Through the Shell Script Anji Shell Programming and Scripting 6 12-06-2010 03:00 PM
Control browser from shell script slak0 Shell Programming and Scripting 2 09-01-2010 06:08 AM
how to disable and enable <control>-c or -z in a shell script islam.said Shell Programming and Scripting 3 02-17-2010 06:46 AM
How to Control Cronjobs using Shell Script?? hanu_oracle Shell Programming and Scripting 8 03-18-2008 11:49 AM



All times are GMT -4. The time now is 08:18 PM.