Timeline for ssh, start a specific shell, and run a command on the remote machine?
Current License: CC BY-SA 3.0
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 11, 2021 at 22:29 | comment | added | Gabriel Staples |
@Gilles'SO-stopbeingevil', please see my follow-up question here: ssh, start a specific shell (ash), and source your environment on the remote machine. My linux device doesn't have bash nor zsh. I'm trying to do this with ash instead.
|
|
| Nov 11, 2021 at 21:46 | comment | added | Gilles 'SO- stop being evil' |
@GabrielStaples On the contrary: exec zsh; . ~/.profile would not read .profile since exec replaces the current shell. If you want zsh to read .zprofile, use exec zsh -l. I don't understand your second comment; how is ash involved?
|
|
| Nov 11, 2021 at 21:42 | comment | added | Gabriel Staples |
Also, I can't get this to work with the ash shell. It seems to forget all things sourced when I include the ash cmd as part of the ssh command as you have done with the zsh.
|
|
| Nov 11, 2021 at 21:42 | comment | added | Gabriel Staples |
Shouldn't exec zsh come before . ~/.profile so that ~/.profile is sourced in the new shell, not the old one?
|
|
| Sep 17, 2017 at 21:42 | comment | added | Nusrat Nuriyev | oh, seems to me , I got it, in case if we need to execute just one command we do not need to start bash shell | |
| Sep 17, 2017 at 21:34 | comment | added | Gilles 'SO- stop being evil' |
@CEOatApartico This is not at all related to the use of the -i switch.
|
|
| Sep 17, 2017 at 21:13 | comment | added | Nusrat Nuriyev | I have already found the solution , that in case of -i switch the -t option must be specified with following patter 'command; bash -l -c "<the actual command>"' not the -t "<the actual command>" as it is described . But thanks for your help, anyway. | |
| Sep 17, 2017 at 20:40 | comment | added | Gilles 'SO- stop being evil' |
@CEOatApartico Using a key is the normal way to use SSH and doesn't prevent the -t option from working. If something is not working for you, ask a new question and be sure to describe your problem precisely (and not what you assume to be the problem).
|
|
| Sep 17, 2017 at 20:14 | comment | added | Nusrat Nuriyev | how the command is changed if I use identity file which is typical for AWS servers? -t option does not work in that case | |
| Apr 13, 2017 at 12:36 | history | edited | CommunityBot |
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
|
|
| Oct 6, 2015 at 23:51 | comment | added | Amelio Vazquez-Reina | Thanks @Gilles. Yes, I do have control over the dot files. I have started a related question here. | |
| Oct 6, 2015 at 10:07 | comment | added | Gilles 'SO- stop being evil' |
@AmelioVazquez-Reina Not conveniently unless you have some control over one of the dot files. You can set the environment variable ZDOTDIR to make zsh look for dot files in a different directory. If you do have some control over the dot files then you can do something like add eval $LC_STARTUP_CODE to $ZDOTDIR/.zshrc and pass the code to execute in the environment variable LC_STARTUP_CODE.
|
|
| Oct 6, 2015 at 0:05 | comment | added | Amelio Vazquez-Reina |
Thanks again for your help. One follow up question here. Any way to run more commands, after the exec zsh command?
|
|
| Sep 15, 2011 at 0:09 | comment | added | Gilles 'SO- stop being evil' |
@intrpc exec replaces the original shell with zsh; without zsh, the original shell would remain in memory until zsh exits and then exit. The main difference is saving a bit of memory, it's not very important. If your login shell is (t)csh, use setenv HOME ~/bob; exec zsh. Finally, since zsh is started with no argument, you get a shell session, like you'd get if you just ran ssh and had zsh as your login shell.
|
|
| Sep 15, 2011 at 0:04 | comment | added | Amelio Vazquez-Reina |
Hmm, when I run ssh -t [email protected] 'HOME=~/bob; exec zsh' I get HOME=~/bob: command not found. I think I am on tcsh. I get the same problem if I try HOME=/home/bob. I tried on bash and zsh. Any clues what may be causing this? Finally, would the syntax above leave me with the ssh session open? (what I want). Thanks again.
|
|
| Sep 14, 2011 at 23:47 | comment | added | Amelio Vazquez-Reina |
Fantastic @Guilles. Your contributions to this site are making it a tremendously useful resource for all of us. Thanks so much, really. By the way, I didn't know about the exec command. How is exec zsh different from calling zsh directly? Why is it important in this particular case?
|
|
| Sep 14, 2011 at 23:45 | vote | accept | Amelio Vazquez-Reina | ||
| Sep 14, 2011 at 23:42 | history | answered | Gilles 'SO- stop being evil' | CC BY-SA 3.0 |