2 CMD results on the same line while rexing in a loop

Folks,
I have a 3 problems. In a sh script, I call a server name from a list and rex to a distant machine to get the boot date.

for i in `cat list`
do
(echo "$i|"; /bin/rexsh $i -l bozo -t10 who -b | cut -d" " -f14-16) >>getBootTimes.out
sleep 1
done

The results are on 2 lines instead of 1.
ServerName1_K044|
Jul 10 05:30
ServerName2_K044|
Oct 2
ServerName3_K044|
Jul 19 14:15
ServerName4_K044|
Sep 29 10:22

  1. I would like to get the info on the same line
  2. with the month & day in a numeric format.
  3. Single digit days have to be managed as well

ServerName1_K044|0710
ServerName2_K044|1002 <-note: no "zero" in front of 2 above Oct 2
ServerName3_K044|0719
ServerName4_K044|0929

Thanks for your consideration.

for 1.

...
do
  (printf "%s|" $i; ...

There is no need for cat:

while read i
do
  : whatever
done < list

echo "$i|" prints a newline. Use printf instead:

printf "%s|" "$i"

Thanks cfa! I'll give that a try. Any tips on converting the Jul 29 to 0729 or Oct 2 to 1002?

month=Jul
day=29

mm=JanFebMarAprMayJunJulAugSepOctNovDec
idx=${mm%%$month*}
mnum=$(( (${#idx} + 4 ) / 3 ))
printf "%02d%02d\n" "$mnum" "$day"

or a more brute force solution

  case $month in
  (Jan) m=1;;
  (Feb) m=2;;
  (Mar) m=3;;
  (Apr) m=4;;
  (May) m=5;;
  (Jun) m=6;;
  (Jul) m=7;;
  (Aug) m=8;;
  (Sep) m=9;;
  (Oct) m=10;;
  (Nov) m=11;;
  (Dec) m=12;;
  esac

Thank you Folks!

---------- Post updated at 04:20 PM ---------- Previous update was at 09:36 AM ----------

while read i
do
: whatever
done < list

When I tried this example, the program ran the first line as expected and did not advance to the second. Tried it with the ":" and without, same results.

while read i
do
: ans=`rexsh $i -l bozo -t10 uptime | cut -d" " -f6`
echo "$i|$ans" >>bootTimes.out

    if  [ $ans -ge 120 ]
     then
            echo "$i|$ans" &gt;&gt;bootThese.out
     else
            echo "$i|$ans" &gt;&gt;bootList2Recent2Work.out
    fi

done < list

Hi.

Try reading your file from another descriptor.

For example:

exec 3< list

while read i <&3
do
    ans=`rexsh $i -l bozo -t10 uptime | cut -d" " -f6`
    echo "$i|$ans" >>bootTimes.out

        if  [ $ans -ge 120 ]
         then
                echo "$i|$ans" >>bootThese.out
         else
                echo "$i|$ans" >>bootList2Recent2Work.out
        fi

done

This may or may not help, but I know that when I have something like:

  while read SERVER do;
    ssh $SERVER some_command
  done < servers.txt

It only does the first one (I guess ssh closes standard input or something when it's done(??))

You guess right. It is easily overcome by using the -n option:

while read SERVER
do
  ssh -n $SERVER some_command
done < servers.txt