I
Ishmael
Howdy,
I'm trying to get a list of clients/users on my network using 'rusers'.
When I run 'rusers' from the command line, the behavior is as follows:
First, it instantaneously prints list of clients/users (perfect) THEN
it hangs for several seconds (I think this is due to a problem with the
client database configuration, over which I have no control). In any
case, I would like to time out the function after a second or so, keep
the first chunk of output, and kill the 'rusers' function.
Unfortunately, it seems as if the output does not become accessible via
the filehandle (see below) unless 'rusers' exits normally (which takes
too long). I've tried turning 'autoflush' on, but this doesn't seem to
work.
Any help would be greatly appreciated! Here's the code:
undef $/; # Try eliminating OUTPUT_RECORD_SEPARATOR
print "Getting user list via rusers\n";
my ($pid, $rusers_out, @tmp);
eval {
local $SIG{ALRM} = sub { die "alarm clock restart\n" };
alarm $rusers_timeout;
eval {
$pid = open F, "rusers -a |" or die "rusers gave error: $!";
F->autoflush(1);
$rusers_out = <F>;
};
alarm 0;
if ($@) {
if ($@ =~ /alarm clock restart/) {
die "'rusers' timed out.\n"; # Create an exception to get out of
outer loop.
}
else {
die($@);
}
}
};
alarm 0;
if ( $@ ne '' ) {
print "$@";
# kill PID with a TERM (terminate) signal. Note: Control-C (INT
signal) also works.
my $num_successfully_killed = kill('TERM', $pid);
if ($num_successfully_killed != 1) {
print "Error: Could not kill rusers after timeout\n";
}
}
print "RUSERS OUTPUT: $rusers_out\n"; # Nothing gets here
exit;
I'm trying to get a list of clients/users on my network using 'rusers'.
When I run 'rusers' from the command line, the behavior is as follows:
First, it instantaneously prints list of clients/users (perfect) THEN
it hangs for several seconds (I think this is due to a problem with the
client database configuration, over which I have no control). In any
case, I would like to time out the function after a second or so, keep
the first chunk of output, and kill the 'rusers' function.
Unfortunately, it seems as if the output does not become accessible via
the filehandle (see below) unless 'rusers' exits normally (which takes
too long). I've tried turning 'autoflush' on, but this doesn't seem to
work.
Any help would be greatly appreciated! Here's the code:
undef $/; # Try eliminating OUTPUT_RECORD_SEPARATOR
print "Getting user list via rusers\n";
my ($pid, $rusers_out, @tmp);
eval {
local $SIG{ALRM} = sub { die "alarm clock restart\n" };
alarm $rusers_timeout;
eval {
$pid = open F, "rusers -a |" or die "rusers gave error: $!";
F->autoflush(1);
$rusers_out = <F>;
};
alarm 0;
if ($@) {
if ($@ =~ /alarm clock restart/) {
die "'rusers' timed out.\n"; # Create an exception to get out of
outer loop.
}
else {
die($@);
}
}
};
alarm 0;
if ( $@ ne '' ) {
print "$@";
# kill PID with a TERM (terminate) signal. Note: Control-C (INT
signal) also works.
my $num_successfully_killed = kill('TERM', $pid);
if ($num_successfully_killed != 1) {
print "Error: Could not kill rusers after timeout\n";
}
}
print "RUSERS OUTPUT: $rusers_out\n"; # Nothing gets here
exit;