Done and done!

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.

# 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; }
Of course the major limitation at this point is only 'a' thru 'p' commands will be available.

In reply to (jeffa) RE: Re: RPC by jeffa
in thread RPC by jeffa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.