The loop does not run as expected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The loop does not run as expected
# 8  
Old 07-05-2006
Hi vgersh99,

Thanks for educated explanation!
But I have bad news from my point of view.
I still have problems with my loop when I use "rsh" command.

My ksh content is :
Code:
#! /bin/ksh

CONF_FILE=nir.conf
export $(< $CONF_FILE)
installLog=/tmp/nir-$$.log
run_install_sr()
{
nawk -F'[=:]' '$1 ~ "^INSTALL_SR_" && $NF = "Y" {print $2}' "${CONF_FILE}" | while read INSTALL_SR_DIR
do
   rsh ${DB_HOST_NAME} "echo $INSTALL_SR_DIR"
done
}
run_install_sr

The configuration file content is:
Code:
DB_LAYER=NO
ADMIN_LAYER=NO
RTESUB_LAYER=NO
DB_HOST_NAME=tornado
ADMIN_HOST_NAME=tornado
RTESUB_HOST_NAME=tornado
RESPONSE_FILE_SR=/tmp/SR.rsp
INSTALL_SR_1=/home/Upgrade_4.7.1/Utilities/Install_SR:Y
INSTALL_SR_2=/home/Upgrade_4.7.2/Utilities/Install_SR:Y
INSTALL_SR_3=/home/Upgrade_4.8/Utilities/Install_SR:Y
INSTALL_SR_4=/home/Upgrade_4.8.1/Utilities/Install_SR:Y

I ran the script:
Code:
bounty: # ./nir.ksh -f nir.conf
/home/Upgrade_4.7.1/Utilities/Install_SR

Again,the loop ran only once on the first iteration!

I'm gonna lose my sanity ....

Any more ideas ?

Thanks a lot in advance,
Nir
# 9  
Old 07-06-2006
Hi folks,

I wanted to update you that finally I found the solution :
I replaced the "while" loop :
Code:
nawk -F'[=:]' '$1 ~ "^INSTALL_SR_" && $NF = "Y" {print $2}' | while read INSTALL_SR_DIR
do
  ..........
done

with "for" loop:

Code:
for INSTALL_SR_DIR in `nawk -F'[=:]' '$1 ~ "^INSTALL_SR_" && $NF = "Y" {print $2}' "${CONF_FILE}"`
do
  ........
done

It works now perfectly!

F.Y.I

Best regards,
Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

For loop not giving expected output

#cat /tmp/input old_array old_dev new_dev new_array 0577 008AB 01744 0125 0577 008AC 01745 0125 0577 008AD 005C8 0125 0577 008AE 005C9 0125 0577 008AF 005CA 0125 0577 008B0 005CB 0125 0577 008B1 005CC 0125 cat test.sh #!/bin/ksh... (4 Replies)
Discussion started by: mbak
4 Replies

2. Shell Programming and Scripting

Trying to run a basic for loop

OS : RHEL 6.1 Shell : Bash I had a similair post on this a few weeks back. But I didn't explain my requirements clearly then. Hence starting a new thread now. I have lots of files in /tmp/stage directory as show below. I want to loop through each files to run a command on each file. I... (8 Replies)
Discussion started by: kraljic
8 Replies

3. Shell Programming and Scripting

Run the for loop in parallel

I have the below code which runs on multiple databases , but this runs one-after-one. I will need this to run in parallel so that i could save a lot of time. Please help!!! Thanks in advance for Db in `cat /var/opt/oracle/oratab |egrep -v "ASM" |grep -v \# |cut -d\: -f1` do { export... (5 Replies)
Discussion started by: jjoy
5 Replies

4. Shell Programming and Scripting

How to run it in the loop??

I have this code awk -F, ' { C5+=$5 C6+=$6 C7+=$7 C8+=$8 R=$5+$6+$7+$8 T+=R } { print $0,R } END { print... (7 Replies)
Discussion started by: nikhil jain
7 Replies

5. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

6. Shell Programming and Scripting

How do I run a shell command in a while loop?

The command is: sic -h irc.freenode.net 2>&1 | tee -a irc.log Where sic is an IRC client, and I'm piping the output to tee in order to log my IRC sessions. I'm trying to handle reconnects by running it in a while loop in the shell process and cat the initial commands into sic's stdin. I... (1 Reply)
Discussion started by: guitarscn
1 Replies

7. Shell Programming and Scripting

For loop to run external program

Hi, I was hoping for help with a for loop to run a program (vina) repeatedly using all the files in a folder as input. Currently my code looks like this: #!/bin/bash FILES=/home/afalk/Desktop/battest/*.pdbqt for f in $FILES do vina --config /home/afalk/Desktop/A.txt --ligand "$f".pdbqt done... (5 Replies)
Discussion started by: oldmanwinter
5 Replies

8. Shell Programming and Scripting

How To Run A For Loop In A Remsh?

Hi all, I'm trying to remsh to another server and then execute a for loop command there but I'm getting unexpected errors and would appreciate any suggestions. Ideally what I want to do is this: for host in `cat host_file` do remsh $host -n " cd /home/ for DATABASE in `ls -d... (5 Replies)
Discussion started by: Korn0474
5 Replies

9. Shell Programming and Scripting

Is there a better way I could have run this loop. (For loop with two variables)

Sorry for such a dreadful title, but I'm not sure how to be more descriptive. I'm hoping some of the more gurutastic out there can take a look at a solution I came up with to a problem, and advice if there are better ways to have gone about it. To make a long story short around 20K pieces of... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

10. Shell Programming and Scripting

Script doesn't work as expected when run on cron

The script checks for free space stats on Oracle. If there are any tablespaces with more than 85% usage it prints the details of the tablespace. If all the tablespaces have more than 15% free space, then "All tablespaces have more than 15 pct free space" must be printed on the screen. When I run... (2 Replies)
Discussion started by: RoshniMehta
2 Replies
Login or Register to Ask a Question