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

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement