LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-26-2007, 10:48 AM   #1
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Blog Entries: 1

Rep: Reputation: 15
Question File status indicator for EOF?


I have the following script:

while read cos;
do
/root/robert/compare_one_cos_lab_mc1_mc2.sh $cos;
done < /tmp/coa2.txt

/tmp/coa2.txt has numberous lines in it, but the loop executes only once. I suspect that after the first call to the subscript, this script thinks it is at end of file, because the subscript reads other files in /tmp, so I need to save the file status before calling the subscript, and restore the file status on return so it will read the next record in /tmp/coa2.txt.

What is the file status flag for EOF, and how do I save it and restore it?

Thanks...

Last edited by steven.c.banks; 12-26-2007 at 12:07 PM.
 
Old 12-26-2007, 11:54 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I don't think that is the problem.

Code:
cat test
line1
line2
line3
Code:
 while read line; do
> echo $line
> while read entry; do
> echo $entry
> done <test
> done <test
line1
line1
line2
line3
line2
line1
line2
line3
line3
line1
line2
line3
One problem with what you have posted is that if a line contains whitespace, the shell will break up $cos.

It also seems strange that you have a subdirectory in /root/. In linux /root is the home directory of the root user and you shouldn't be running normally as root. Did you mean to type "/home/" instead?

It also looks like some of the programs like diff and cmp from coreutils may be able to do what you want. I'm just guessing from the title of your script.
 
Old 12-26-2007, 12:20 PM   #3
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Question File status indicator for EOF

Thanks for your reply. The records in the file do not have any whitespace; just one field. Running scripts as root and using /root/robert was the practice before I was hired here, and not really relevant to this issue. The subscript has several diffs in it.

Is there an alternative way to read a file line by line?
 
Old 12-26-2007, 01:21 PM   #4
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44

Original Poster
Blog Entries: 1

Rep: Reputation: 15
I did some tracing within /root/robert/compare_one_cos_lab_mc1_mc2.sh by putting an exit after each statement to find out where the bogus end of file condition is coming from, and I found that after the following statement, when I return to the calling script, it thinks it is at end of file in /tmp/coa2.txt.

plink -ssh -pw xxxxxxxx root@y.y.y.y "/root/robert/get_cos_listing.sh $servicecat" > /tmp/mc1$servicecat

How do I prevent the above statement from setting the bogus end of file condition? plink is a PuTTY utility we use instead of rsh.
 
Old 12-26-2007, 05:33 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
I don't believe that the line you posted effects the EOF of coa2.txt. If you had a line the redirected output to cao2.txt, then it would. Check if the plink command returns. It might operate like "exec" causing the current shell to be replaced.

Last edited by jschiwal; 12-26-2007 at 07:43 PM.
 
Old 12-27-2007, 06:55 AM   #6
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44

Original Poster
Blog Entries: 1

Rep: Reputation: 15
A friend suggested I use this alternate method of reading the file line by line. I don't know why, but this fixed the problem.

exec 3< /tmp/coa2.txt
until [ $done ]
do
read <&3 cos
if [ $? != 0 ]; then
done=1
continue
fi
/root/robert/compare_one_cos_lab_mc1_mc2.sh $cos;
done
 
  


Reply

Tags
eof, files, multiple



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
500 EOF instead of reponse status line in perl script Sherlock Programming 7 05-16-2007 06:52 AM
how to umark EOF status on scsci tape mayankh Linux - Hardware 1 10-20-2006 02:14 PM
Led status indicator: just because of PS1? xpucto Solaris / OpenSolaris 6 01-27-2006 05:38 AM
battery status indicator not working with dell inspiron shirishs Mandriva 8 02-10-2004 06:24 PM
Dial Up Status Indicator claudius753 Linux - Newbie 2 01-31-2004 10:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration