# Run commands at shell access from env

**URL:** <https://discourse.openondemand.org/t/run-commands-at-shell-access-from-env/599>\
**Category:** Feature Requests and Roadmap Discussion\
**Tags:** feature-request, question\
**Created:** [November 12, 2019, 1:42pm UTC](https://discourse.openondemand.org/t/run-commands-at-shell-access-from-env/599 "2019-11-12T13:42:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajuvercr](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ajuvercr](https://discourse.openondemand.org/u/ajuvercr)\
**Post date:** [November 12, 2019, 1:42pm UTC](https://discourse.openondemand.org/t/run-commands-at-shell-access-from-env/599/1 "2019-11-12T13:42:25Z")

</div>

Hey, I would like to execute a command at shell access.  
For me it’s ok if the user can see the commands so I would just do something like  
`term.write("module swap cluster/"+process.env.CLUSTER);` so it swaps in the correct cluster.

The only problem I find is that de shell app doesn’t behave like a ‘normal’ app, it seems to ignore my **template/before.sh** that I would use to set the **CLUSTER** env variable.

I’ve been struggling with this for a long time now 😕

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [November 12, 2019, 3:10pm UTC](https://discourse.openondemand.org/t/run-commands-at-shell-access-from-env/599/2 "2019-11-12T15:10:57Z")

</div>

It’s probably easier to add an `sh` file to your clusters’ `/etc/profile.d/` folder. Especially if you manage your infrastructure through tooling like Ansible, Puppet, Chef, and so on.

Otherwise you’ll have to hack the shell source code. Not sure I’d recommend that, but I can look into it if you really need. Again, I’m sure it’d be easier (simpler and probably more maintainable) to just drop a file in that folder. If you don’t already use that tooling, a simple Ansible script can easily drop a file across hundreds of nodes.

---

<div class="post-metadata">

**Author:** ![ajuvercr](https://avatars.discourse-cdn.com/v4/letter/a/9f8e36/32.png) [@ajuvercr](https://discourse.openondemand.org/u/ajuvercr)\
**Post date:** [November 12, 2019, 3:21pm UTC](https://discourse.openondemand.org/t/run-commands-at-shell-access-from-env/599/3 "2019-11-12T15:21:37Z")

</div>

Hm yes, but our configuration has only one login node, from which you can execute `module swap cluster/xxx`. This sets everything ready to run commands on that cluster. But you are still sshed to that same login node.

---

<div class="post-metadata">

**Author:** ![efranz](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/efranz/32/27_2.png) [@efranz](https://discourse.openondemand.org/u/efranz)\
**Post date:** [November 12, 2019, 3:23pm UTC](https://discourse.openondemand.org/t/run-commands-at-shell-access-from-env/599/4 "2019-11-12T15:23:36Z")

</div>

This looks very similar to [Possible to make shell-access app start on a compute node via "srun --pty bash"?](https://discourse.openondemand.org/t/possible-to-make-shell-access-app-start-on-a-compute-node-via-srun-pty-bash/586/5)

I opened an issue on that to support configuring the shell app easily with custom commands. I’ll add this use case to that issue. Meanwhile, you could use the interim solution that I suggested in that Discourse topic, or modify the shell app directly.

---

<div class="post-metadata">

**Author:** ![westburg.2](https://avatars.discourse-cdn.com/v4/letter/w/0ea827/32.png) [@westburg.2](https://discourse.openondemand.org/u/westburg.2)\
**Post date:** [May 26, 2022, 4:11pm UTC](https://discourse.openondemand.org/t/run-commands-at-shell-access-from-env/599/5 "2022-05-26T16:11:40Z")

</div>

Closed on May 26, 2022, 4:11pm UTC


