Skip to content

Instantly share code, notes, and snippets.

@jfayad
Last active August 12, 2017 21:08
Show Gist options
  • Save jfayad/86fa1258e3d9eddba08f707838123934 to your computer and use it in GitHub Desktop.
Save jfayad/86fa1258e3d9eddba08f707838123934 to your computer and use it in GitHub Desktop.
defp aegir_commad(command) do
# open ssh connection to terminal
case ssh_connect do
{:ok, connection} ->
#str = SSHEx.stream connection, '#{command}', exec_timeout: 120000
ping = "ping -c " <> to_string(:rand.uniform(5)) <> " www.google.com"
IO.puts ping
str = SSHEx.stream connection, '#{ping}'
IO.inspect str
Enum.reduce_while(str, {}, fn(x, acc)->
case x do
{:stdout,row} ->
#IO.puts row
{:cont, {}}
{:stderr,row} ->
#IO.puts row
{:cont, {}}
{:status,status} ->
#close the SSH connection
IO.inspect(connection)
:ssh.close(connection)
{:halt,{:ok, status}}
{:error,reason} ->
#close the SSH connection
:ssh.close(connection)
{:halt,{:error, reason}}
end
end)
{:error, reason} ->
{:error, reason}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment