Run ssh command from R Markdown (bash)

孤街醉人 提交于 2020-01-15 08:13:06

问题


I am working on an automated report using R Markdown which shows retention profile plots for which I am querying data from Redshift. Since I need to ssh into my connection I figured I'd add my ssh commands as a bash command in my markdown script. I checked to make sure simple commands work (e.g., cd, mkdir) which all work fine but it seems to get stuck on the ssh command.

Does anybody have an idea whether this does not work because of the ssh command or because of R markdown/ knitr (it works fine if I paste my ssh code in my terminal). It can recognise the ssh command when I just type ssh but it gets stuck when I specify the ports/endpoints. I'm afraid I cannot share a reproducible example without sharing my ssh specs.

---
title: "example script"
author: "Tim Faber"
date: "1/29/2018"
output: html_document
runtime: shiny
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Create ssh tunnel


```{r, engine='bash'}

ssh -N -L portid:datasource:portid ubuntu@..

```

回答1:


Sorry, I think my answer is largely incomplete, but I hope it could help.
As you, I cannot achieve to create a SSH tunnel. I think that bash chunks are not persistent, so I wonder how it would be possible to create such a connexion.
However, I succeed in sending remote commands:

---
title: "Untitled"
output: html_document
runtime: shiny
---

```{bash}
ssh user@xxx.yyy.zz.kk 'cd Documents;ls -l;'
```

I don't use Redshift myself, and I don't know if you can achieve your task with ssh remote commands.



来源:https://stackoverflow.com/questions/48624434/run-ssh-command-from-r-markdown-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!