0

I am going totally crazy!

When I run this bash (prof of concept) script and feed it fast enough, it looses cycles:

# cat sample 
#!/bin/bash
tail -n 0 -f log | while read l
do
    SSH_CMD=$( ssh myhost.sample.com 'ls' )
    X=$( ping -c3 $l )
    echo $( echo "$X" | grep 'time=' | tail -1 | sed 's/.*\(time=.*\) .*/\1/' )
done 

# ./sample&
[1] 32434
# echo 8.8.8.8 >> log
time=5.17
# #->THIS IS OK!
# echo -e "8.8.8.8\n8.8.8.8\n8.8.8.8" >> log
time=4.98
# #->DAMN! It runs only once instead of three times

Same happens if I issue repeated and fast enough:

# echo 8.8.8.8 >> log

Why does the while loop run only once ("loosing" cycles) instead of three times?

Note: if I comment the line with $( ssh ... )

#SSH_CMD=$( ssh myhost.sample.com 'ls' )

or replace it with

SSH_CMD=$( sleep 3 && echo "blahhhshshs" )

and issue a:

    # echo -e "8.8.8.8\n8.8.8.8\n8.8.8.8" >> log
        time=4.98
        time=4.88
        time=5.12

Then I get my expected output with three lines. It seems like using command substitution with ssh makes so that while loop looses cycles. Can anyone explain why this overrun happens and how to avoid it, still using $( ssh .. ) (which in fact I need in order to collect data)?

Cheers, AaWnSd

aAWnSD
  • 124
  • 10

0 Answers0