# from server sub get_commands() { open CONF, 'query.conf' or die "No config file found: $!\n"; while () { next if /^#/; chomp; my ($command, $query) = split(/\t/, $_); $commands{$command} = $query; } close CONF; } sub send_commands { my $rhost = shift; my @commands = sort keys %commands; &log_msg("Request for command list from $rhost"); return join(":", @commands); } # and from the client sub get_commands { my $answer; my $i = 'a'; eval { $answer = $conn->rpc('send_commands', $host) }; die "Server $rhost not responding\n" if $@; map { $commands{$i++} = $_ } split(":", $answer); } sub print_menu { print '#' x 30, "\n"; map { print "# $_) $commands{$_}\n" } sort keys %commands; print "# q) quit\n"; print '#' x 30, "\n"; print "Enter choice: "; } # the main processing loop for the client $SIG{ALRM} = sub { die "TIMEOUT" }; &print_menu; while (my $arg = <>) { last if $arg =~ /q/; chomp $arg; my $answer; eval { alarm(10); $answer = $conn->rpc('run', $commands{$arg}, $host) }; alarm(0); }; warn "$queries{$arg} timed out - $host could be down\n" if $@ =~ /TIMEOUT/; print $answer; &print_menu; }