while loop ending prematurely in a bash script
I have a problem with the script below:
Code:
This is running on Solaris. I appreciate any help. |
Bump, to give it another shot.
|
A few things that sound a little strange to me:
1) you are feeding the loop with the first argument on the script's commandline ("done <$1"). So -I guess- this $1 must be a filename. What's in that file? 2) You are reading the file line-by-line. Because of this line: "$line | cat >>output.txt" I conclude there are shell-executable command inside that file. But on the other hand the lines seem to contain "<user>@servername", because you are using them for ssh-ing. These are conflicting meanings for the contents of the file you giva your script as the first argument. 3) This is probably where your problem is: The awk-line doesn't mention any input source, so it's reading from stdin, which comes from the same file as the loop is reading from! This is wrong, because when your script starts, it reads he first line from the file into the "line" variable with "while read line". Then is executes the awk command, which will read the rest of the file in just one go, leaving nothing to read for the second run of the loop, so the loop will end. |
Hi ,
i also have the same problem just doing this while read list do whoishe=`ssh ${list} whoami ` echo ${whoishe} :${list} >> otherfile done < hostnames its a simple command. whenever i enter the wrong password it is going to the next box in the list but when the correct password is entered it executes properly and just ends the script. doesn't not continue with the list. it is breaking the loop. But when tried scp it goes through the list. please advice thanks |
hi
changed the way the loop works and works fine file list in `cat hostname` do whoishe=`ssh ${list} whoami ` echo ${whoishe}:${list} >> otherfile done < hostnames i don't know is it the way the While loop and the done < hostname works hope this helps others |
Hko,
The line "$line|cat>>output.txt" shouldn't have been in there when I posted the code. I am using a file for the first parameter that contains a list of server names. This code does not work either. Well it works but doesn't loop. Code:
while read line |
Yes.
Even though a command is given on ssh's command line, ssh is still reading stdin (which is your server-name-file). So after ssh executed for the first time the file containing the server names will be read until the end-of-file by ssh, leaving nothing to read for the read-line-loop. To prevent this from happening use the "-n" option for ssh. Try: Code:
#!/bin/bash |
I completely misread what you posted before. Thank you very much for help. I really appreciate it.
|
All times are GMT -5. The time now is 05:15 PM. |