#!/usr/bin/perl -w
# spd.pl - the SQL*Plus daemon server
use strict;
use Expect;
use Socket;
# set up expect
# -- timeout after about 10 minutes
my $timeout = 600;
# -- scan for the SQL*Plus prompt
my $prompt = 'SQL>';
my $exp = new Expect();
$exp->raw_pty(1);
$exp->log_stdout(0);
$exp->spawn('sqlplus','/nolog') die "unable to spawn sqlplus: $!";
$exp->expect($timeout,'-ex',$prompt) die $exp->error();
print $exp "set sqlprompt $prompt;\n";
$exp->expect($timeout,'-ex',$prompt) die $exp->error();
$exp->clear_accum();
my $name = "/tmp/sp_$ENV{USER}";
unlink($name);
socket(S,PF_UNIX,SOCK_STREAM,0) die "socket: $!";
bind(S,sockaddr_un($name)) die "bind: $!";
listen(S,SOMAXCONN) die "listen: $!";
while(accept(C,S))
{
# single threaded to avoid confusion
my $cmd = <C>;
$cmd =~ s/[\r\n]*$//g;
print $exp $cmd,"\n";
if ($cmd =~ /^exit$/mi)
{
print C "exit.\n";
close C;
last;
}
$exp->expect($timeout,$prompt) die $exp->error();
print C $exp->before();
close C;
}
$exp->soft_close();
close S;
unlink($name);
exit;
#!/usr/bin/perl -w
# spc.pl
use Socket;
use strict;
my $cmd = join(' ',@ARGV);
my $name = "/tmp/sp_$ENV{USER}";
my $proto = getprotobyname('udp');
socket(S,PF_UNIX,SOCK_STREAM,0) or die "socket: $!";
select S; $ = 1; select STDOUT;
connect(S,sockaddr_un($name)) or die "connect: $!";
print S $cmd,"\n";
print while (<S>);
close(S);
exit;