Unix Shell - Ksh output garbled/out-of-sync

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2007 > Ksh output garbled/out-of-sync





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Ksh output garbled/out-of-sync
govindrjujare@gmail.com

2007-05-10, 1:19 am

Can somebody explain this ? -- thx

/tmp> cat ./1.sh
#!/bin/ksh

for name in 1 2 3 4 5 6 7 8 9 10
do
/bin/echo "<$name>"
/bin/cat /etc/passwd | head -1 | tail
done

/tmp> ./1.sh
<1>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
<2>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
<3>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
<4>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
<5>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
<6>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
<7>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
<8>
<9>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
<10>
root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh

govindrjujare@gmail.com

2007-05-10, 1:19 am

On May 9, 8:28 pm, govindrjuj...@gmail.com wrote:
> Can somebody explain this ? -- thx
>
> /tmp> cat ./1.sh
> #!/bin/ksh
>
> for name in 1 2 3 4 5 6 7 8 9 10
> do
> /bin/echo "<$name>"
> /bin/cat /etc/passwd | head -1 | tail
> done
>
> /tmp> ./1.sh
> <1>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> <2>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> <3>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> <4>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> <5>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> <6>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> <7>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> <8>
> <9>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh
> <10>
> root:x:0:1:HOSTNAME Super-User:/:/usr/bin/ksh


Looks like problem with "head". Happening on Solaris 5.8.

Bill Marcum

2007-05-10, 7:29 am

On 9 May 2007 19:20:15 -0700, govindrjujare@gmail.com
<govindrjujare@gmail.com> wrote:
>
>
> On May 9, 8:28 pm, govindrjuj...@gmail.com wrote:
>
> Looks like problem with "head". Happening on Solaris 5.8.
>

Try adding "wait" before "done". What version of ksh is this?
What happens if you use the builtin echo instead of /bin/echo?


--
Heard that the next Space Shuttle is supposed to carry several Guernsey cows?
It's gonna be the herd shot 'round the world.
Janis

2007-05-10, 1:27 pm

On 10 Mai, 11:54, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 9 May 2007 19:20:15 -0700, govindrjuj...@gmail.com
>
> <govindrjuj...@gmail.com> wrote:
>
>
>
>
>
>
> Try adding "wait" before "done". What version of ksh is this?
> What happens if you use the builtin echo instead of /bin/echo?
>
> --
> Heard that the next Space Shuttle is supposed to carry several Guernsey cows?
> It's gonna be the herd shot 'round the world.


And while experimenting; what's the result if you remove all
superfluous processs from
[vbcol=seagreen]

head -1 </etc/passwd

Does this also produce the disordered output?

Janis

govindrjujare@gmail.com

2007-05-10, 1:28 pm

On May 10, 5:54 am, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 9 May 2007 19:20:15 -0700, govindrjuj...@gmail.com
>
>
>
> <govindrjuj...@gmail.com> wrote:
>
>
>
>
>
>
> Try adding "wait" before "done". What version ofkshis this?
> What happens if you use the builtin echo instead of /bin/echo?
>
> --
> Heard that the next Space Shuttle is supposed to carry several Guernsey cows?
> It's gonna be the herd shot 'round the world.- Hide quoted text -
>
> - Show quoted text -


Nice suggestion.

"wait" fixed the problem. "sleep 1" also fixed it.
Ksh Version M-11/16/88i on Solaris 5.8.
The cksums for /usr/bin/ksh are -

2378417754 209136 /bin/ksh
2378417754 209136 /usr/5bin/ksh
2378417754 209136 /usr/bin/ksh

The problem occured with built-in "echo" also. Same for built-in
"print" and "printf".
Moreover when I did "whence echo" even thoough it shows "echo", when I
run
"truss echo".... it did a execve on /usr/bin/echo.


govindrjujare@gmail.com

2007-05-10, 1:28 pm

On May 10, 9:00 am, Janis <janis_papanag...@hotmail.com> wrote:
> On 10 Mai, 11:54, Bill Marcum <marcumb...@bellsouth.net> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> And while experimenting; what's the result if you remove all
> superfluous processs from
>
>
> head -1 </etc/passwd
>
> Does this also produce the disorderedoutput?
>
> Janis- Hide quoted text -
>
> - Show quoted text -



That suggestion worked. No more garbled output.

I ran the original script as-is on couple of more other systems with
Solaris 5.8. On some the output seems ok
and on some others, it gets unordered. I guess it varies with cpu
load. Whenever I am not able to reproduce the
problem, I just add few more "head -1" commands and the output gets
unordered.

I am leaning towards the possibilities that there is something wrong
with the configuration of our systems or
"head" is doing something mysterious with STDIN.





govindrjujare@gmail.com

2007-05-10, 7:19 pm

On May 10, 1:17 pm, govindrjuj...@gmail.com wrote:
> On May 10, 9:00 am, Janis <janis_papanag...@hotmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> That suggestion worked. No more garbledoutput.
>
> I ran the original script as-is on couple of more other systems with
> Solaris 5.8. On some theoutputseems ok
> and on some others, it gets unordered. I guess it varies with cpu
> load. Whenever I am not able to reproduce the
> problem, I just add few more "head -1" commands and theoutputgets
> unordered.
>
> I am leaning towards the possibilities that there is something wrong
> with the configuration of our systems or
> "head" is doing something mysterious with STDIN.- Hide quoted text -
>
> - Show quoted text -


Did I mention that the behaviour is not consistent for each run ? I
modified the script to check for
several iterations. Here is what worked and what did not.

========================================

#!/bin/ksh

integer i=0
while [[ $i -lt 1000 ]]
do
echo "marker"

# unordered
# /bin/cat /etc/passwd | /bin/head -1 | /bin/tail

# ordered
# /bin/head -1 </etc/passwd | /bin/tail

# ordered
# /bin/head -1 /etc/passwd | /bin/tail

# ordered
# /bin/cat /etc/passwd | /bin/head -1 | /bin/tail
# wait

i=$i+1
done
========================================


When you open one of the commented blocks and run the script as ---

../1.sh | uniq | wc -l

It should print 2000. For the "unordered" block, it hardly prints
about 1600.




govindrjujare@gmail.com

2007-05-11, 1:17 pm

On May 10, 2:56 pm, govindrjuj...@gmail.com wrote:
> On May 10, 1:17 pm, govindrjuj...@gmail.com wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Did I mention that the behaviour is not consistent for each run ? I
> modified the script to check for
> several iterations. Here is what worked and what did not.
>
> ========================================

> #!/bin/ksh
>
> integer i=0
> while [[ $i -lt 1000 ]]
> do
> echo "marker"
>
> # unordered
> # /bin/cat /etc/passwd | /bin/head -1 | /bin/tail
>
> # ordered
> # /bin/head -1 </etc/passwd | /bin/tail
>
> # ordered
> # /bin/head -1 /etc/passwd | /bin/tail
>
> # ordered
> # /bin/cat /etc/passwd | /bin/head -1 | /bin/tail
> # wait
>
> i=$i+1
> done
> ========================================

>
> When you open one of the commented blocks and run the script as ---
>
> ./1.sh | uniq | wc -l
>
> It should print 2000. For the "unordered" block, it hardly prints
> about 1600.- Hide quoted text -
>
> - Show quoted text -


I am able to reproduce the problem on several Solaris 5.8 systems now.
It
is starting to look like a problem with ksh. The following code prits
a number
anywhere from 1900 to 2000.

integer i=0
while [[ $i -lt 1000 ]]
do
/bin/echo marker 2>&1
/bin/cat /etc/passwd 2>&1 | /bin/echo "this" 2>&1 | /bin/wc -
l 2>&1
i=$i+1
done > out 2>&1
uniq out | wc -l


govindrjujare@gmail.com

2007-05-14, 1:20 pm

On May 11, 1:43 pm, govindrjuj...@gmail.com wrote:
> On May 10, 2:56 pm, govindrjuj...@gmail.com wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> I am able to reproduce the problem on several Solaris 5.8 systems now.
> It
> is starting to look like a problem withksh. The following code prits
> a number
> anywhere from 1900 to 2000.
>
> integer i=0
> while [[ $i -lt 1000 ]]
> do
> /bin/echo marker 2>&1
> /bin/cat /etc/passwd 2>&1 | /bin/echo "this" 2>&1 | /bin/wc -
> l 2>&1
> i=$i+1
> done > out 2>&1
> uniq out | wc -l- Hide quoted text -
>
> - Show quoted text -



Tested it on about a dozen Solaris 5.8 systems. Found
out that the problem is with ksh version built in 2003 (I
also verified this by copying the /usr/bin/ksh to the
affected systems and running the test script).

Good Ksh:
=======
/tmp> /usr/ccs/bin/what /usr/bin/ksh
/usr/bin/ksh:
Version M-11/16/88i
SunOS 5.8 Generic Patch November 2001

Problematic Ksh:
============
/tmp> /usr/ccs/bin/what /usr/bin/ksh
/usr/bin/ksh:
Version M-11/16/88i
SunOS 5.8 Generic 110662-12 Mar 2003







govindrjujare@gmail.com

2007-05-25, 7:17 pm

On May 14, 12:31 pm, govindrjuj...@gmail.com wrote:
> On May 11, 1:43 pm, govindrjuj...@gmail.com wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Tested it on about a dozen Solaris 5.8 systems. Found
> out that the problem is withkshversion built in 2003 (I
> also verified this by copying the /usr/bin/kshto the
> affected systems and running the test script).
>
> GoodKsh:
> =======
> /tmp> /usr/ccs/bin/what /usr/bin/ksh
> /usr/bin/ksh:
> Version M-11/16/88i
> SunOS 5.8 Generic Patch November 2001
>
> ProblematicKsh:
> ============
> /tmp> /usr/ccs/bin/what /usr/bin/ksh
> /usr/bin/ksh:
> Version M-11/16/88i
> SunOS 5.8 Generic 110662-12 Mar 2003- Hide quoted text -
>
> - Show quoted text -


It turned out to be a bug in ksh (ksh88). The new ksh (ksh93) does not
suffer from this problem.



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com