1

The following code works fine in one system and not the other with same specs.

System A:

ksh --version
version         sh (AT&T Research) 93u+ 2012-08-01
uname -a
Linux ServerA 2.6.32-431.5.1.el6.x86_64 #1 SMP Fri Jan 10 14:46:43 EST 2014 x86_64 x86_64 x86_64 GNU/Linux

Code:

#!/bin/ksh
cd /home/path/
if [ `ls -1 *.log 2>/dev/null |  wc -l` -gt 0 ] ; then
echo "Log files are more than Zero"
  for f in `ls -1 *.log` ; do
        echo $f
        sleep 1
  done
fi

Output:

Log files are more than Zero
file1.log
file2.log
file3.log

System B:

ksh --version version sh (AT&T Research) 93u+ 2012-08-01

uname -a
Linux ServerB 2.6.32-431.5.1.el6.x86_64 #1 SMP Fri Jan 10 14:46:43 EST 2014 x86_64 x86_64 x86_64 GNU/Linux

Code:

#!/bin/ksh
cd /home/path/
if [ `ls -1 *.log 2>/dev/null |  wc -l` -gt 0 ] ; then
echo "Log files are more than Zero"
  for f in `ls -1 *.log` ; do
        echo $f
        sleep 1
  done
fi

Output:

Log files are more than Zero

And it hangs forever .....

Any thoughts why ??

Kevin
  • 183
  • 2
  • 11
  • change `for f in \`ls -1 *.log\` ; do ` to `for f in *.log` for starters. AND are no spaces in your log filenames? (I hope not!). FINALLY, just to confirm, you intend that the output of `ls` is "slowed-down" by the `sleep 1`? Good luck. – shellter Jul 08 '15 at 23:31
  • The issue is that the same code works on similar other system A. I can user $() which i know works. but I'm trying to find out what is causing this to hang on system B. – Kevin Jul 09 '15 at 06:26
  • `set -vx` is the next line of debugging. With this turned on can you see if it is the for loop that is not moving forward, or the first execution of `echo $f` that is hanging? Again, spaces or other odd characters in the log file? How many files in each dir on both servers? Exactly the same? or 30 on 1 server, and millions plus on the other? (I've seen it happen!). Good luck. – shellter Jul 09 '15 at 10:26
  • set -vx has the same effect. it just hangs again with any additional information. After some debugging and analysis I notice that it is happening for this specific set of log files in the System B. I manually created a ton of zero byte files and some with spaces in the names and the same code seems to run fine. But it hangs on the actual log files. I tried removing a bunch of them at a time and after certain number of file are removed it seems to run fine . But could not figure out the bad file/files that is causing this behavior :-( .... Any ideas Please ? – Kevin Jul 10 '15 at 00:42
  • All shells have a limit to the size of command-line arguments (total length) that they will process. When I've bumped into this in the past, an error message is displayed. Are you redirecting `stderr` and not telling us? Otherwise, I'm stumped. I'm pretty sure if you search here for `[ksh] command-line size limit` you'll find something. (I don't have time today). I did find this Q/A with an answer by your's truly, that may be of some help http://stackoverflow.com/questions/14371326/what-is-the-maximum-number-of-characters-that-the-ksh-variable-accepts ;Be sure to post your solution.Good Luck. – shellter Jul 10 '15 at 15:04

0 Answers0