我试图在命令行中通过Plink打开SSH隧道以运行一些R脚本,但我无法让R脚本运行,并且当它们运行时未创建隧道,因此与我的数据库的连接崩溃。
Plink代码如下所示:
plink.exe -ssh [username]@[hostname] -L 3307:127.0.0.1:3306 -i "[SSH key]" -N
后跟运行R脚本的代码
"C:\Program Files\R\R-3.2.1\bin\x64\R.exe" CMD BATCH qidash.R
我似乎无法让隧道保持打开状态以运行R脚本。但是,我可以单独打开隧道并运行代码。
最佳答案
我假设您在批处理文件中有两个命令,如下所示:
plink.exe -ssh [username]@[hostname] -L 3307:127.0.0.1:3306 -i "[SSH key]" -N
"C:\Program Files\R\R-3.2.1\bin\x64\R.exe" CMD BATCH qidash.R
那么确实
R.exe
永远不会执行,因为plink.exe
无限期地运行。您必须并行运行命令:
start
命令在后台运行plink.exe
。 killtask
完成后,使用plink
命令杀死后台R.exe
进程。 R.exe
之前稍作停顿,以允许Plink建立隧道。 rem Open tunnel in the background
start plink.exe -ssh [username]@[hostname] -L 3307:127.0.0.1:3306 -i "[SSH key]" -N
rem Wait a second to let Plink establish the tunnel
timeout /t 1
rem Run the task using the tunnel
"C:\Program Files\R\R-3.2.1\bin\x64\R.exe" CMD BATCH qidash.R
rem Kill the tunnel
taskkill /im plink.exe
关于batch-file - 通过Plink打开SSH隧道,并通过命令行批处理文件运行R脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32193256/