pachadotdev / analogsea

Digital Ocean R client
https://pacha.dev/analogsea/
Apache License 2.0
155 stars 24 forks source link

Should have some way to capture ssh output #79

Closed wch closed 9 years ago

wch commented 10 years ago

Sometimes you want to run an ssh command and capture the output. (I want to use it to run docker ps and check whether a docker container is still running.) It would be useful if droplet_ssh could return the text.

This is how I'm checking the running containers right now:

droplet_docker_running <- function(droplet, user = "root") {
  temp_remote <- tempfile("docker_ps", tmpdir = "/tmp")
  temp_local <- tempfile("docker_ps")

  droplet_ssh(droplet, user = user, paste("docker ps -q >", temp_remote))
  droplet_download(droplet, user = user, temp_remote, temp_local)
  on.exit(unlink(temp_local))

  readLines(temp_local)
}

droplet_docker_running(revdep, user = "analogsea")
# [1] "ee6c7f61ff19"

Note that I'm not using the docklet_* functions because they seem to be behind the droplet_* functions in functionality. Also, it might be worth revamping the docklet API; I'll put it in another issue.

sckott commented 10 years ago

@wch I made you an admin on this repo in case you want to make changes more easily

wch commented 10 years ago

Excellent, thanks!

hadley commented 10 years ago

Doing this is a little fiddly - I think we just need to thread an intern = TRUE argument all the way to do_system. Need to take the code from devtools::system_check that retrieves the status code in different ways depending on the value of intern

sckott commented 9 years ago

@wch is this handled yet in harbor ?

wch commented 9 years ago

Yup. It's basically the same method as above - it simply redirects output to a file in /tmp on the remote machine, and then downloads that file to the local one.

https://github.com/wch/harbor/blob/623ca356950f7db238d637ab96b98b16cff48d22/R/droplet.R#L12-L15

Feel free to close this issue.

sckott commented 9 years ago

great, closing