So I've found that running ssh remote "<command>" runs the remote shell in non-interactive mode, thus it doesn't source the same startup scripts as if it were an interactive shell. My issue is that I need to source these startup scripts when running a remote command, but I don't actually need an interactive shell, just the startup scripts. Is there anyway I can force the non-interactive shell to source the same startup scripts for an interactive shell?
Asked
Active
Viewed 205 times
0
mtveezy
- 601
- 2
- 10
- 20
-
how would this work? the scripts are on your local machine and you want to source them in the remote shell? – Mircea Mar 02 '16 at 19:13
-
Sorry for the confusion, I want it to source the scripts on the remote machine, in the remote shell – mtveezy Mar 03 '16 at 18:49
1 Answers
0
You could have your "command" do the sourcing you want. For example, it could become ". .bashrc; command"
Or you could invoke your command with bash -i "..." to tell bash to start in interactive mode even if it normally wouldn't have.
Or you could pass in the BASH_ENV shell variable that points to the startup script that you want, since bash will source that file when started in non-interactive mode.
Eric Renouf
- 13,300
- 3
- 41
- 62
-
could you elaborate on how to tell bash to start in interactive mode? I tried `ssh remote bash -i "bin/some_script.sh"` but it still doesn't work – mtveezy Mar 03 '16 at 18:56
-
Are you sure that the variables you want are in your `.bashrc` then? Your example works with a dummy script for me, though it won't do aliases if that's what you're trying to use. Then you might want to look at http://stackoverflow.com/questions/1615877/why-aliases-in-a-non-interactive-bash-shell-do-not-work – Eric Renouf Mar 03 '16 at 19:08