【问题标题】:Open SSH tunnel via Plink and run R Scripts via command line batch file通过 Plink 打开 SSH 隧道并通过命令行批处理文件运行 R 脚本
【发布时间】:2015-08-24 23:22:47
【问题描述】:

我试图通过命令行中的 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 脚本。但是,我可以单独打开隧道并运行代码。

【问题讨论】:

    标签: batch-file ssh cmd plink


    【解决方案1】:

    我假设您在一个批处理文件中一个接一个地有两个命令,例如:

    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
    • R.exe 完成后,使用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
    

    【讨论】:

    • 谢谢!效果很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-06
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多