Skip to content

Instantly share code, notes, and snippets.

@fredhsu
Last active January 29, 2016 02:40
Show Gist options
  • Save fredhsu/6324345 to your computer and use it in GitHub Desktop.
Save fredhsu/6324345 to your computer and use it in GitHub Desktop.
SSH to router using Elixir
:ssh.start
{:ok, cref} = :ssh.connect('10.55.3.1', 22, [{:user, 'user'}, {:password, 'password'}])
{:ok, cid} = :ssh_connection.session_channel(cref, 5000)
:ssh_connection.exec(cref, cid, String.to_char_list("show ver | xml | no-more"), 3000)
#:ssh_connection.exec(cref, cid, String.to_char_list("show core"), 3000)
# need to do a receive on the cref(pid)
#flush() -- useful to find out what the result will look like
receive do
{:ssh_cm, _, {:data, _, _, d}} -> IO.puts d
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment