I am trying to open an SSH tunnel via Plink in the command line to run a few R scripts and I cannot get the R scripts to run and when they do run the tunnel was not created, so the connection to my database crashes.
The Plink code looks like this:
plink.exe -ssh [username]@[hostname] -L 3307:127.0.0.1:3306 -i "[SSH key]" -N
Followed by the code to run the R scripts
"C:\Program Files\R\R-3.2.1\bin\x64\R.exe" CMD BATCH qidash.R
I cannot seem to get the tunnel to stay open to run the R script. However, I can open the tunnel separately and run the code.
I assume you have the two commands in a batch-file one after another like:
Then indeed the
R.exe
is never executed as theplink.exe
runs indefinitely.You have to run the commands in parallel:
start
command to runplink.exe
in the background.killtask
command to kill the backgroundplink
process after theR.exe
finishes.R.exe
to allow the Plink to establish the tunnel.