diff --git a/command-client b/command-client new file mode 100755 index 0000000000000000000000000000000000000000..1e1264f630cf6fd4c4a2db5bbf88392abb342a9b --- /dev/null +++ b/command-client @@ -0,0 +1,39 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Data::Dumper; +use IO::Socket; + +my $host = shift @ARGV || "146.169.22.26"; # shell4.. +my $port = 55001; + + +# +# my $socket = connect_server(); +# connect to our server (trying several times if +# necessary), return the socket we receive. +# In case of repeated failure, return undef. +# +sub connect_server() +{ + warn "trying to connect to $host:$port\n"; + foreach (1..5) { + my $socket = new IO::Socket::INET('PeerAddr' => $host, + 'PeerPort' => $port, + 'Proto' => 'tcp'); + return $socket if $socket; + warn "trying again...\n"; + sleep 1; + } + return undef; +} + +my $socket = connect_server(); +die "can't connect to $host:$port\n" unless $socket; +warn "connected to $host..\n"; +my $line = join( " ", @ARGV ); +print $socket "$line\n"; +while( <$socket> ) +{ + print; +} diff --git a/command-listener b/command-listener index dc90ad23a8d2d0fd42a5ecc9fa7f9013603f318a..7e293c0d02108c19c4801108d7e6e6a88e59ca3d 100755 --- a/command-listener +++ b/command-listener @@ -1,7 +1,8 @@ #!/usr/bin/perl # # command-listener: daemon that listens for a connection on a -# port and runs a single specific command, sending the +# port, reads a single line of text (arguments) and runs a single +# specific command with those arguments, gathering and sending the # results of running that command back to the client. # use strict; @@ -18,7 +19,7 @@ use csglib::Log; my $logfile = "/tmp/command-listener.log"; # command to run.. -my $command = "/bin/date"; # example:-) +my $command = "/bin/ls"; # example:-) my $port = shift @ARGV || 55001; my $quit = 0; @@ -110,7 +111,16 @@ sub connection_loop ($$) # sub converse () { - system( $command ); + $log->warn( "reading line from client" ); + my $args = <STDIN>; + unless( $args ) + { + $log->warn( "converse: eof from client" ); + print "client: gimme some args:-)\n"; + return; + } + chomp $args; + system( "$command $args" ); }