You are not logged in.

#1 2018-04-18 07:50:05

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,393

[SOLVED] lightweight way to wait for an host to come down?

Right now i'm using the following:

while ! ping 192.168.117.28 -c 1 -w 1 &>/dev/null ; do sleep 0.5 ; done

I need it to be reactive, so i just set a timeout of 1 second and a sleep of 1/2 second, but this involves calling "ping" executable too often!

I wonder if there is a tool that exits as soon as the host stops answering, ping options dont seems to help.

Thanks!

Last edited by kokoko3k (2018-04-18 09:30:14)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#2 2018-04-18 08:49:38

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [SOLVED] lightweight way to wait for an host to come down?

With perl you can do this:

#!/usr/bin/perl
  
my ($host, $timeout, $family) = @ARGV;

use Net::Ping;
$p = Net::Ping->new();
while ( $p->ping($host, $timeout, $family) ) {
  select(undef, undef, undef, 0.25);
}
$p->close();

| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#3 2018-04-18 09:30:05

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,393

Re: [SOLVED] lightweight way to wait for an host to come down?

Almost no cpu use with:

./wait.down.pl 192.168.117.28 0.1

Thanks!

-EDIT
It seems to work, but just to be sure, is the following edit sufficient to invert the logic and wait for the host to be up too?

while ( ! $p->ping($host, $timeout, $family) ) {

Last edited by kokoko3k (2018-04-18 09:33:19)


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#4 2018-04-18 09:43:04

progandy
Member
Registered: 2012-05-17
Posts: 5,190

Re: [SOLVED] lightweight way to wait for an host to come down?

That should work.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

Board footer

Powered by FluxBB