I'm stuck on sending the result back to the client.
I think if I read the perlipc's doc as suggested by beable, it'll help
but in any case here's the code:
server.script:
use Socket;
($Program = $0) =~ s@^.*/@@;
$file = "/tmp/socket.$Program";
$addr = sockaddr_un($file);
socket(SERVER, PF_UNIX, SOCK_STREAM, 0) || die "Could not create socke
+t: $!";
unlink("$file");
bind(SERVER, $addr) || die "Could not bind: $!";
listen(SERVER,SOMAXCONN) || die "Could not listen: $!";
while (accept(CLIENT,SERVER)) {
$cmd = <CLIENT>;
if ($cmd) {
$time = &timeStamp;
open(CMD, "ssh2 rob\@machine_b $cmd |");
@results = <CMD>;
close(CMD);
print @results;
}
}
client.script:
use Socket;
($Program = $0) =~ s@^.*/@@;
$file = "/tmp/server.script";
&Message("/home/me/run_script -r -s a1 -avg");
sub Message {
my ($cmd) = @_;
my $level = 1;
if (socket(SOCKET, PF_UNIX, SOCK_STREAM, 0)) {
connect(SOCKET, sockaddr_un($file)) || die "Could not connect:
+ $!";
print SOCKET $cmd;
close SOCKET;
} else {
print "I couldn't connect";
}
}
OK, the client.script sends the query to server.script,
and server.script runs the cmd & prints it. how do i get it
to return the results to the client.script so the client.script
can print the result?
(I think i should go and read the perlipc's doc)
thanx...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.