Run ssh command from R Markdown (bash)

2019-07-13 03:39发布

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@..

```

标签: r ssh r-markdown
1条回答
在下西门庆
2楼-- · 2019-07-13 04:11

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.

查看更多
登录 后发表回答