通过Plink打开SSH隧道,并通过命令行批处理文件运行R脚本

我试图在命令行中通过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

然后确实从未执行plink.exe因为plink.exe无限期运行。


您必须并行运行命令:

  • 您可以使用start命令在后台运行plink.exe
  • R.exe完成后,使用killtask命令killtask后台plink进程。
  • 在运行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

参考更多解答: Open SSH tunnel via Plink and run R Scripts via command line batch file ,转载请保留出处通过Plink打开SSH隧道,并通过命令行批处理文件运行R脚本及作者信息

Statement: We respect knowledge and authors. Since the content comes from the Internet and is intended for scientific research, any reprinters should retain the author's signature and origin. If you are the author of the content and feel in dispute, please contact email: 1076545519@qq.com. We will find out the situation and deal with it in time. We sincerely thank the author for his hard work.


更多:plink