I went overboard on this issue. The server has a config file that it reads the actual *nix commands from, along with a pneumonic name (i.e. inodes='df -i') and stores the key-value pairs in a hash. When a client connects to the server, the server sends the pneumonics, so the client never sees the actual command.
Of course the major limitation at this point is only 'a' thru 'p' commands will be available.# from server sub get_commands() { open CONF, 'query.conf' or die "No config file found: $!\n"; while (<CONF>) { 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; }
In reply to (jeffa) RE: Re: RPC
by jeffa
in thread RPC
by jeffa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |