# Scripting with User Switch Command

**URL:** <https://forum.elixirforum.com/t/scripting-with-user-switch-command/28474>\
**Category:** Questions\
**Tags:** remote\_shell, user-switch-command\
**Created:** [January 22, 2020, 1:00pm UTC](https://forum.elixirforum.com/t/scripting-with-user-switch-command/28474 "2020-01-22T13:00:59Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Aduril](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/aduril/32/18040_2.png) [@Aduril](https://forum.elixirforum.com/u/Aduril)\
**Post date:** [January 23, 2020, 10:54am UTC](https://forum.elixirforum.com/t/scripting-with-user-switch-command/28474/3 "2020-01-23T10:54:48Z")

</div>

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:

```elixir
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 🙂.

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

---

_[View the full topic](https://forum.elixirforum.com/t/scripting-with-user-switch-command/28474)._
