-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisup
More file actions
executable file
·44 lines (37 loc) · 795 Bytes
/
isup
File metadata and controls
executable file
·44 lines (37 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
use warnings;
use strict;
use IO::Socket;
(my $host, my $port) = @ARGV;
die "No host specified\n" unless $host;
#do a tcp check if a port was specified else do icmp
if($port) {
until( my $sock = new IO::Socket::INET (
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => 2)){next;}
alertup();
} else { #icmp
#use systems ping utility because it is setuid root
#and you don't want this script to be
while(1) {
system("ping -c 1 $host > /dev/null 2>&1");
if($? eq 0) {
alertup();
last;
} elsif ($? & 127) { #signal killed ping
#die "Died from signal\n";
exit(1);
}
}
}
sub alertup {
if($ENV{'DISPLAY'}) {
if(!fork) {
system("xmessage -center $host is up");
}
} else { #DISPLAY not set
print "$host is up\n";
}
}