Choose Language Hide Translation Bar
Highlighted
vince_faller
Super User

ssh tunnel to database.

I'm trying to write a script that uses an SSH tunnel to a database in order to access it.  I'm not able to get it to work.  Anyone else tried this before?  

I've already setup my ssh key and I can run the open database and have it return if I run the ssh command in a cmd window separate from the script but I'd like it if I can integrate everything into the JSL (so users don't have to remember to open the tunnel).  

 

Names default to here(1);
rp = Run Program(
	executable("ssh.exe"), 
	Options({"-tt", "-L 1414:localhost:1414", "test@test.com"}), 
	ReadFunction( "text" )
);

dt = open database(
	"cxn_string",
	"SELECT * FROM Test",
	"Test"
);
rp << Write EOF();

 

Thanks in advance.  

Vince Faller - Predictum
0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Staff (Retired)

Re: ssh tunnel to database.

I'm guessing RunProgram waits forever, trying to get all the output from ssh.exe.

ReadFunction("text") which means RunProgram should block until the program finishes, then return any text the program produced (probably none in your example.)

This won't block and will copy any output to the log:

ReadFunction(
	Function( {this},
		write(this << read);
	)
)

If that works, rp (in your original example) will be the runprogram object rather than the returned text.

 

https://community.jmp.com/t5/Uncharted/JSL-to-Control-Raspberry-Camera/ba-p/226243 uses plink.exe, which is probably equivalent to ssh.exe. I had to use 

rp << Write( "exit\!n" );

to get a clean disconnect; I thought rp<<writeeof should work but was not successful.

Craige

View solution in original post

2 REPLIES 2
Craige_Hales
Staff (Retired)

Re: ssh tunnel to database.

I'm guessing RunProgram waits forever, trying to get all the output from ssh.exe.

ReadFunction("text") which means RunProgram should block until the program finishes, then return any text the program produced (probably none in your example.)

This won't block and will copy any output to the log:

ReadFunction(
	Function( {this},
		write(this << read);
	)
)

If that works, rp (in your original example) will be the runprogram object rather than the returned text.

 

https://community.jmp.com/t5/Uncharted/JSL-to-Control-Raspberry-Camera/ba-p/226243 uses plink.exe, which is probably equivalent to ssh.exe. I had to use 

rp << Write( "exit\!n" );

to get a clean disconnect; I thought rp<<writeeof should work but was not successful.

Craige

View solution in original post

Highlighted
vince_faller
Super User

Re: ssh tunnel to database.

D'ah.  Should have thought of that.  Thanks.  

Vince Faller - Predictum
0 Kudos