Last active
August 12, 2017 21:08
-
-
Save jfayad/86fa1258e3d9eddba08f707838123934 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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