Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Using Net::SSH2 with DBI

by oiskuu (Hermit)
on Jan 21, 2016 at 12:45 UTC ( [id://1153270]=note: print w/replies, xml ) Need Help??


in reply to Re: Using Net::SSH2 with DBI
in thread Using Net::SSH2 with DBI

Here's some skeleton code to try. I haven't tested it much, but it seems to connect alright.

#! /usr/bin/perl use strict; use warnings; use Socket; use POSIX; sub named_socket_spawn { my $code = shift; ref $code eq 'CODE' or return; my ($serv, $conn); socket($serv, AF_UNIX, SOCK_STREAM, PF_UNSPEC) || die "socket: $!"; my $sname = tmpnam(); bind($serv, sockaddr_un($sname)) || die "bind: $!"; listen($serv, 1) || die "listen: $!"; my $pid = fork() // die "fork: $!"; if ($pid) { close $serv; return $sname; } accept($conn, $serv) || warn "accept: $!"; unlink($sname) || warn "unlink: $!"; open STDIN, "<&", $conn; open STDOUT, ">&", $conn; close $serv; close $conn; exit $code->(); } use DBD::mysql; #my $sqlsock = named_socket_spawn(sub{exec "ssh host -W host:3306"}); my $sqlsock = named_socket_spawn(sub{ exec "nc localhost 3306" }); my $dsn = "DBI:mysql:database=test;mysql_socket=$sqlsock"; my $dbh = DBI->connect($dsn, "test", "hunter5");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1153270]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-20 04:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found