Weird loop break,- please Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Weird loop break,- please Help
# 1  
Old 07-13-2009
Weird loop break,- please Help

Hi all, im doing this script in which i read from a logfile line by line, my problem is this:

The script was working fine until i added this statement to SSH into another machine to look for some data, it enters and retrieves the data just fine, but for some strange reason after it goes thru the case statement it exits the loop as if there was nothing else to be read from the file... if you remove this ssh statement it doesnt match anything on the case statement AND it actually continues to read the next line...

Code:
echo $LINE | grep -i "transition to ok"
if [ $? -eq 0 ]
then
DIMMR=`ssh root@20.0.0.4 "ssh module-$CURRMOD \"ipmitool sel get 0x$HEXREG\"" | grep -i "event data" | cut -d: -f2 | cut -c2-7`
echo "A replacement of DIMM $DIMMR has ocurred"
fi

case $DIMMR in

"000011")   A1=0 ;;
"000012")   A2=0 ;;
"000021")   B1=0 ;;
"000022")   B2=0 ;;
"000031")   C1=0 ;;
"000032")   C2=0 ;;
"000041")   D1=0 ;;
"000042")   D2=0 ;;
esac

echo $A1
echo "---------------------------------------------------------------------------------"

done < /tmp/mfg/ecclog.txt


I'm not sure how to get around this, perhaps something i missed in the case? or one of those hideous subshell weird behaviours due to the SSH?

i attached the files for you to see, thank you.
# 2  
Old 07-13-2009
Oh boy... am i stupid.... i swear i did searched but i could not find anything like it, right after posting it showed me a list of related threads and there is was exactly what i was looking for:

https://www.unix.com/shell-programmin...hile-loop.html

Quote:
hey, guys, thanks for all the input!

I got another easier solution, adding -n after ssh will do the trick,

#!/bin/bash
while read dir file
do

ssh -n test@192.1.1.1 "ls -tl /$dir/$file"

done < /tmp/dirandfile
Apparently this is caused by the ssh reading my file and not leaving anything for the while loop... Smilie

Quote:
-n Redirects stdin from /dev/null (actually, prevents reading from stdin). This must be
used when ssh is run in the background. A common trick is to use this to run X11 pro-
grams on a remote machine. For example, ssh -n shadows.cs.hut.fi emacs & will start
an emacs on shadows.cs.hut.fi, and the X11 connection will be automatically forwarded
over an encrypted channel. The ssh program will be put in the background. (This does
not work if ssh needs to ask for a password or passphrase; see also the -f option.)
Anyway, thanks for you time guys Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Break in for loop

in my python script i have loop like below: for item in itemlist: if <condition>: <code> else: <code> if <condition>: if <condition>: <code> else: for type in types: if... (1 Reply)
Discussion started by: ctrld
1 Replies

2. Shell Programming and Scripting

Basic FOR loop with break

Oracle Linux : 6.4/bash shell In the below I want to break out of the loop when it enters the 5th iteration. #!/bin/bash for i in 1 2 3 4 5 6 do echo "$i" if echo "Oh Nooo... i = $i. I need to stop the iteration and jump out of the loop" then break fi done But, it only... (3 Replies)
Discussion started by: John K
3 Replies

3. Shell Programming and Scripting

Break the outer loop

Hi I'm comparing same files names which are in different folders . The first for loop for the files in DAY1 folder and the second for loop for the files in DAY2 folder . the first IF condition is for checking whether the file names are equal the second If condtion is for checking the... (4 Replies)
Discussion started by: smile689
4 Replies

4. Shell Programming and Scripting

For loop to break apart word

notimes=5 word=excellency the word excellency contains 10 letters. 10 letters divided by 2 = 5. which means, 5 two-groups of letters are in the word excellency. i need to perform a function on each group of letters. but the only thing i can think of is the following, which i just know... (5 Replies)
Discussion started by: SkySmart
5 Replies

5. Shell Programming and Scripting

For loop with dashes in filenames causing weird output

Hi again, What i'm trying to accomplish here is search a large directory for certain filesames, read from a txt file and looping through it. For instance, one of my target names from the loop file is: 1ad55f47-c342-496b-a46d-ba7de0f1b434 My loop is constructed thusly, run in a directory... (2 Replies)
Discussion started by: Karunamon
2 Replies

6. Shell Programming and Scripting

break while loop in BASH

Hi gurus, I have the following part of code which I am using for treating input #!/bin/bash while ]; do arg=$1; shift case $arg in -u) users="$1" shift ;; -g) groups="$1" shift ;; ... (4 Replies)
Discussion started by: wakatana
4 Replies

7. Shell Programming and Scripting

How to break a loop if condition is met

I am having trouble figuring this code I want to grep a text from a file and if it match certain text it break out of the loop or it should continue searching for the text Here is what I have written but it isn't working while true f=`grep 'END OF STATUS REPORT' filename` do if ... (9 Replies)
Discussion started by: Issemael
9 Replies

8. Shell Programming and Scripting

How to break the while loop???(Very Urgent)

H, I am running the following log.sh shell script. $no_of_ps=7 while do echo "hello $no_of_ps" ps_file=`tail -$no_of_ps /tmp/A380_RFS24/test.ls | head -1` no_of_ps=`expr $no_of_ps - 1` echo "package is: $ps_file" >> /tmp/A380_RFS24/log/A380_RFS24.log ps_file1=`echo $ps_file| sed... (1 Reply)
Discussion started by: sunitachoudhury
1 Replies

9. Shell Programming and Scripting

Why for loop is acting weird

Hey i have a small script in which i check if a file with that pattern exists or not. If present then i go ahead with further processing. In the present situation i have only one file with that name and for loop is reading twice. Here is the script. And the output of debug mode. Please help.... (5 Replies)
Discussion started by: dsravan
5 Replies

10. Shell Programming and Scripting

ksh how user can break out of loop

Hi Folks, I am trying to write a simple script which involves a potentially infinite loop repeating a number of tasks quickly. I would like to enable the user to break out of this when he/she wishes (some key stroke) but not to break out of the script (i.e. which is what happens when a user... (4 Replies)
Discussion started by: beckett
4 Replies
Login or Register to Ask a Question