"while read ..." loop exiting after reading only one record


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users "while read ..." loop exiting after reading only one record
# 1  
Old 02-02-2010
"while read ..." loop exiting after reading only one record

Greeting,

The following script completes after reading only one record from the input file that contains many records. I commented out the "ssh" and get what I expect, an echo of all the records in the input.txt file. Is ssh killing the file handle?

On the box "uname -a" gives "SunOS Server01 5.10 Generic_127127-11 sun4u sparc SUNW,Sun-Fire-V490".



Code:
#!/bin/ksh
\rm -f /tmp/x/*
let i=0
IFS=,
while read server dir; do
let i=i+1
echo "Record $i: ${server} ${dir}"
dir_=`echo ${dir} | tr "[/]" "[_]"`
ssh ${server} find ${dir} -follow  >/tmp/x/${server}${dir_}.txt
es=$?
echo "exit status = $es\n"
done < input.txt

# 2  
Old 02-02-2010
Hi.

Try using the -n option of ssh.
# 3  
Old 02-03-2010
Thanks, that did make the script work more the way I was expecting.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Failure: if grep "$Var" "$line" inside while read line loop

Hi everybody, I am new at Unix/Bourne shell scripting and with my youngest experiences, I will not become very old with it :o My code: #!/bin/sh set -e set -u export IFS= optl="Optl" LOCSTORCLI="/opt/lsi/storcli/storcli" ($LOCSTORCLI /c0 /vall show | grep RAID | cut -d " "... (5 Replies)
Discussion started by: Subsonic66
5 Replies

2. Shell Programming and Scripting

Bash - How to do a "read -p" inside a while loop?

Hi there guys! I was trying to do: while read line; do if ; then read -p "Press Enter to continue..." cont=0 fi echo $line let cont++ done < file.txt However, I have read that the read -p would not work in a while loop... I was wondering if there is any other way to... (2 Replies)
Discussion started by: rplae
2 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Solaris

Solaris 10 "Exiting (caught signal 11)"

I get an error after the initializing screen. I am using a DVD/ROM to boot up the installation on a Dell Inspiron 1520. Segmentation fault - core dumped. I have tried to restart multiple times. Please help (1 Reply)
Discussion started by: Jimasaurus
1 Replies

5. Ubuntu

What is solution for this error "tar: Exiting with failure status due to previous errors"?

Does anyone know what is solution for this error ?tar: Exiting with failure status due to previous errors from last 3 days I am trying to take backup of home/user directory getting again and again same error please anyone give me solution (8 Replies)
Discussion started by: Akshay Hegde
8 Replies

6. Shell Programming and Scripting

Read from "list1" and list matches in "list2"

I want to print any matching IP addresse in List1 with List 2; List 1 List of IP addresses; 161.85.58.210 250.57.15.129 217.23.162.249 74.76.129.101 30.221.177.237 3.147.200.59 170.58.142.64 127.65.109.33 150.167.242.146 223.3.20.186 25.181.180.99 2.55.199.32 (3 Replies)
Discussion started by: lewk
3 Replies

7. Shell Programming and Scripting

Purpose of "read" and "$END$" in ksh ?

Hi, Could anyone please shed some light on the following script lines and what is it doing as it was written by an ex-administrator? cat $AMS/version|read a b verno d DBVer=$(/usr/bin/printf "%7s" $verno) I checked that the cat $AMS/version command returns following output: ... (10 Replies)
Discussion started by: dbadmin100
10 Replies

8. Shell Programming and Scripting

"Odd" behavior exiting shell script

Is it normal behavior for a shell script that terminates to terminate its parent shell when executed with the "." option? For example, if I have the example script (we'll name it ex.sh): #!/bin/sh if then echo "Bye." exit 2 fi And I execute it like this: >./ex.sh It... (6 Replies)
Discussion started by: DreamWarrior
6 Replies

9. Shell Programming and Scripting

read -p "prompt text" foo say "read: bad option(s)" in Bourne-Shell

Hallo, i need a Prompting read in my script: read -p "Enter your command: " command But i always get this Error: -p: is not an identifier When I run these in c-shell i get this error /usr/bin/read: read: bad option(s) How can I use a Prompt in the read command? (9 Replies)
Discussion started by: wiseguy
9 Replies

10. Shell Programming and Scripting

how to request a "read" or "delivered" receipt for mails

Dears, I've written a script which allows me to send mails in different formats with different attaches. Now I still want to add a feature to this script. My users would like to be able to receive a "read" or "delivered" receipt for their mails. The script send mails on behalve of an specific... (1 Reply)
Discussion started by: plelie2
1 Replies
Login or Register to Ask a Question