LINUX.ORG.RU
ФорумAdmin

ping shell script


0

0

Как сделать скрипт который бы пинговал хост и в случае отстутствия ответа делал то-то?

anonymous

Его надо написать !!!

anonymous
()

На самом деле можно использовать код возврата ping.

Вот из man: If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0. This makes it possible to use the exit code to see if a host is alive or not.

Behemoth
()


#!/bin/sh
if ping -q -c 1 test.host.ru > /dev/null
then
exit 0
else
echo YESSSS
fi

John
()

А у меня короче ;)

#!/bin/sh

ping -c1 -q host > /dev/null || echo "I can't receive echo reply ;("


anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.