# הפעלת פקודות rails מ-Bash המארח

**URL:** <https://meta.discourse.org/t/executing-rails-commands-from-host-bash/189126>\
**Category:** Self-hosting\
**Created:** [4 במאי,‏ 2021,‏ 11:04am UTC](https://meta.discourse.org/t/executing-rails-commands-from-host-bash/189126 "2021-05-04T11:04:41Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![sven2](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@sven2](https://meta.discourse.org/u/sven2)\
**Post date:** [4 במאי,‏ 2021,‏ 11:04am UTC](https://meta.discourse.org/t/executing-rails-commands-from-host-bash/189126/1 "2021-05-04T11:04:42Z")

</div>

Hi all,

I want to execute automated user clean up tasks from the host Bash. Manually, I run

```plaintext
/var/discourse/launcher enter app
rails c
UserDestroyer.new(Discourse.system_user).destroy(User.find_by_username_or_email("user@example.com"), delete_posts: false) 

```

I have a long list of user names from a text file that need to be removed. Manually executing this is not reasonable. I tried to wrap the deletion command in a bash script. When executing rails c with the `launcher app` subcommand, the Redis connection fails:

```plaintext
/var/discourse/launcher run app "echo \"User.find_by_username_or_email('user@example.com')\" | rails c"
Failed to report error: Error connecting to Redis on localhost:6379 (Errno::EADDRNOTAVAIL) 2 Error connecting to Redis on localhost:6379 (Errno::EADDRNOTAVAIL) subscribe failed, reconnecting in 1 second.

```

However, when I compare the environments with `export` between `launcher enter app` and `launcher run app`, they look pretty much identical. What am I missing? `launcher run` starts in `/` while `launcher enter` directly enters `/var/www/discourse`. Using a cd before executing rails does not help.

Any hints? Thanks!

---

_[View the full topic](https://meta.discourse.org/t/executing-rails-commands-from-host-bash/189126)._
