Help with for loop within two scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with for loop within two scripts
# 1  
Old 09-07-2006
Help with for loop within two scripts

Hello All,
I have a problem in executing the following - I have a monitor.sh that kicks off and then the config.sh which sends message to the monitor.sh. So If I recieve a Failed message, the monitor.sh will kill the config.sh process and outputs a message.

monitor.sh:
message= FAILED
DEPLOY_PID=ps -aef | grep create_config.sh | grep -v grep | awk {'print $2'}
MONITOR_PID=ps -aef | grep STEMonitor | grep -v grep | awk {'print $2'}
if [[ $message = FAILED ]]; then
kill -9 $DEPLOY_PID
echo "Deployment Failed"
echo " Please check the log for details"
kill -9 $MONITOR_PID
exit 1
fi

The problem is, I am not getting how to make monitor.sh run throughout in an infinite loop and keep checking config.sh and die after the deployment is done or failed. For the second part,I am killing monitor.sh after killing the config.sh and also adding another line to kill monitor.sh process at the end of config.sh

I am failing to loop monitor.sh to loop through on config.sh. Please help

-Chiru
# 2  
Old 09-07-2006
I think you may want to search the forums for "co-process" or "coprocess" - this is a feature of ksh you will probably want to use.
# 3  
Old 09-08-2006
In a simple way, I was implementing it in this way,
test.sh:
#!/bin/ksh
echo "test1"
./monitor.sh &
echo "test2"

monitor.sh
#!/bin/ksh
filename = $STE_ANT_DIR/deployment/logs/$APP_SHORTNAME_deployment.log
cd $STE_ANT_DIR/deployment
DEPLOY_PID=ps -aef | grep create_config.sh | grep -v grep | awk {'print $2'}
MONITOR_PID=ps -aef | grep STEMonitor | grep -v grep | awk {'print $2'}
message= $JAVA_HOME/java -classpath deploy.jar STEMonitor $filename
count=1
while ( count < 2 )
do

if [[ $message = FAILED ]]; then
kill -9 $DEPLOY_PID
kill -9 $MONITOR_PID
exit 1
fi
done

when I run monitor.sh:
./monitor.sh: cannot open 2: No such file or directory

is the error??
Any ideas please

Chiru
# 4  
Old 09-08-2006
Please correct me if i am wrong.

You want to check continuously if the config.sh has sent "FAILED" message. If it does then you want to terminate the config.sh.

what i will suggest is set up a cron job which will check periodically and accordingly terminate the processes. This will help you to get rid of the infinite loop thing.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk loop using array:wish to store array values from loop for use outside loop

Here's my code: awk -F '' 'NR==FNR { if (/time/ && $5>10) A=$2" "$3":"$4":"($5-01) else if (/time/ && $5<01) A=$2" "$3":"$4-01":"(59-$5) else if (/time/ && $5<=10) A=$2" "$3":"$4":0"($5-01) else if (/close/) { B=0 n1=n2; ... (2 Replies)
Discussion started by: klane
2 Replies

2. Shell Programming and Scripting

Calling multiple scripts from another scripts

Dear all, I am working on script which call other shell scripts in a loop but problem is from second script am not able to come out. Here is the snippet:- #!/bin/bash HSFILE=/root/Test/Components.txt LOGFile=/opt/domain/AdminDomain/application/logs... (3 Replies)
Discussion started by: sharsour
3 Replies

3. Shell Programming and Scripting

Calling scripts from with scripts

Hi all, I'm wondering if you could give me some advice. I am new to scripting and am getting rather frustrated that i can get my script to call another script if certain criteria is met, via command line, but I cannot get the same script to work thru the cron jobs. My first script monitors... (8 Replies)
Discussion started by: echoes
8 Replies

4. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

5. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

6. Shell Programming and Scripting

Running scripts within scripts from cron

Hi all, I have set up a cron job which calls another shell script shell script which in turn calls a Java process. The cron tab looks so. 0,30 7-18 * * 1-5 /u01/home/weblogic/brp/bin/checkstatus.sh >> /u01/home/weblogic/logs/checkstatus.log The checkstatus.sh scripts looks like this. ... (4 Replies)
Discussion started by: sirbrian
4 Replies

7. Shell Programming and Scripting

Help with Script using rsh and scripts within scripts

Hi, I've written a script that runs on a Database server. It has to shutdown the Application server, do an Oracle Dump and then restart the Application server. Its been a long time since I wrote any shells scripts. Can you tell me if the scripts that I execute within my script will be executed... (3 Replies)
Discussion started by: brockwile1
3 Replies

8. UNIX for Dummies Questions & Answers

Profile scripts versus rc scripts....

what is the difference between login and profile scripts versus the rc scripts? (1 Reply)
Discussion started by: rookie22
1 Replies

9. Shell Programming and Scripting

i want to combine two awk scripts which is having same loop and filelist

hi, to all give me some idea below scripts file=`cat filelist` for filename in $file do awk '{ if ($0 ~ /system/ && flag == 0) { flag=1; print $0; } else if ($0 ~ /system/ && flag == 1) { printf("%s SYSLAY %s %s %s\n",$1,$3, $4, $5); } else print $0; }' $filename >... (6 Replies)
Discussion started by: LAKSHMI NARAYAN
6 Replies
Login or Register to Ask a Question