У меня есть небольшой код для пинга в al oop:
#!/system/bin/sh
_count=0
_target="dns.google.com"
echo "target :: $_target"
while true;
do
_time="$(date +%H%M%S)"
_count=$((_count + 1))
echo "::::::::::::::::::LOOP"
echo "time :: $_time"
echo "counter :: $_count"
ping -w 1 -c 1 $_target >/dev/null 2>&1 &&
echo "$? ... is reachable" ||
echo "$? ... is down"
done
Я звоню с терминала android (используя SManager). Следует проверить доступность хоста с помощью пинга в al oop. Проблема в том, что я получаю реальный ответ только на первый пинг, а все остальные - плохие (вывод):
$ /system/bin/sh /storage/emulated/0/pinger.sh
target :: dns.google.com
::::::::::::::::::LOOP
time :: 174912
counter :: 1
0 ... is reachable
::::::::::::::::::LOOP
time :: 174912
counter :: 2
1 ... is down
::::::::::::::::::LOOP
time :: 174913
counter :: 3
1 ... is down
::::::::::::::::::LOOP
time :: 174914
counter :: 4
1 ... is down
.
..
...etc.
В чем причина такого поведения?
Лукас
РЕДАКТИРОВАТЬ 2:
Новый скрипт:
#!/system/bin/sh
_count=0
_target="dns.google.com"
echo "target :: $_target"
while true;
do
_time="$(date +%H%M%S)"
_count=$((_count + 1))
echo "::::::::::::::::::LOOP"
echo "time :: $_time"
echo "counter :: $_count"
ping -w 1 -c 1 $_target
done
Вывод:
$ /system/bin/sh /storage/emulated/0/pinger.sh
target :: dns.google.com
::::::::::::::::::LOOP
time :: 205444
counter :: 1
PING dns.google.com (8.8.4.4) 56(84) bytes of data.
64 bytes from dns.google (8.8.4.4): icmp_seq=1 ttl=64 time=7.40 ms
--- dns.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 7.404/7.404/7.404/0.000 ms
::::::::::::::::::LOOP
time :: 205445
counter :: 2
PING dns.google.com (8.8.4.4) 56(84) bytes of data.
--- dns.google.com ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 999ms
::::::::::::::::::LOOP
time :: 205447
counter :: 3
PING dns.google.com (8.8.4.4) 56(84) bytes of data.
--- dns.google.com ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
.
..
...etc.