Aduril

Aduril

Scripting with User Switch Command

Hello there,
to improve the workflow of my team I want to make it easier for them to connect to a remote system (aka our stage environment and our production environment).

Currently the workflow looks as following

./start-iex me 127.0.0.1 #script that set cookies and stuff
iex(me@127.0.0.1)1> Node.connect :"app@IP.OF.STAGE.ENV"
true
iex(me@127.0.0.1)3> #CTRL+G
User switch command
 --> r 'app@IP.OF.STAGE.ENV'
 --> c 2
Eshell V10.5  (abort with ^G)
(app@IP.OF.STAGE.ENV)1> #CTRL+G again
User switch command
 --> r 'app@IP.OF.STAGE.ENV' 'Elixir.IEx'
 --> c 3
iex(app@IP.OF.STAGE.ENV)1> #iex shell on remote system

As you can see this is rather tedious and error prone (how often I used the wrong quotes here…).
So my question is:
Does anybody know a way to enter the User Switch Command in a way that is scriptable. My overall goal would be a script that allows people to simply connect to one of our deployed stages.

Any ideas?

Marked As Solved

Nicd

Nicd

I have used Expect for this, as it is designed for automating usage of interactive programs.

I no longer use the script but here it is for reference: refresh.exp · master · Mikko Ahlroth / mebe · GitLab – it should help you get started in case you go with Expect.

Note that on line 14, send " " sends the ctrl+g IIRC. It may not be copied correctly if you copy it with a browser so you may want to download the file directly. (And indeed if I copy it to this forum, it’s rendered as send "a"!)

EDIT: Note that there is also a --remsh option for IEx. Maybe that already does what you need, at least partly?

Also Liked

Aduril

Aduril

Thanks @Nicd,

I have implemented it as expect-script now and will try to improve it. For others with a similar problem, here is my current solution that seems to do the trick:

set username [lindex $argv 0]
set app_ip [lindex $argv 1] 
spawn ./start-iex $username

expect "iex" { send "Node.connect :\"app@$app_ip\"" }
expect "iex" { send "^G" } # this might break while copy-pasting - it is the CTRL+G command
expect -- " -->" { send "r 'app@$app_ip' \n" }
expect -- " -->" { send "c 2\n" }
expect "(app@*" { send "^G" } # see above
expect -- " -->" { send "r 'app@$app_ip' 'Elixir.IEx'\n" }
expect -- " -->" { send "c 3\n" }

interact

I have not used expect before, so if you see any unnecessary parts let me know :slight_smile:.

And if anybody knows a way to enter the user switch command mode within an elixir script, let me know.

Last Post!

BlindingDark

BlindingDark

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44608 311
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement