SSH then change Shell
Asked Answered
B

1

23

Potentially a real easy question but I was wondering if anybody can kindly provide some advice.

To accomplish a repeating task, I am constantly logging into a remote Solaris server using credentials given to us from our system admin. However, each time I log in, I must change shell (from csh -> bash) as the specific task must be run using BASH.

Although it is not a major problem doing this, I find the changing to bash shell somewhat tedious as I must repeat this task several times a day, and also occasionally may forget to change shells before running the task, etc (also I prefer BASH too so).

Is there a way where I can ssh and change default shell in one line so I can start immediately with the script I want on the remote server? Note, I do not what to change any log in files (like .login or .cshrc) as the remote server & the credentials are shared an not specifically for me. I don't want to change the default shell either on the server either as, again, the server & the credentials are used by several people.

Would anybody have any ideas how to get around such a problem? Any suggestions would be greatly appreciated.

Brout answered 28/7, 2014 at 10:48 Comment(1)
related serverfault.com/questions/162018/…Lupelupee
F
33

SSH usually executes the command you pass it as an argument and then disconnects. You'll need three options set to get your interactive session to work:

  • ssh -t will force the pseudo-tty allocation necessary for you to interact with the remote command you're asking SSH to run
  • bash -l will start an interactive login shell
  • csh -l -c will start an interactive login shell in csh, and then execute the command that follows

To just launch a different shell (i.e., your default is csh, and you want to launch bash):

ssh -t <user>@<server> "bash -l"

To pickup the csh environment first, we start the interactive shell, and then pass the command to switch to bash:

ssh -t <user>@<server> 'csh -l -c "bash"'
Foist answered 28/7, 2014 at 12:48 Comment(5)
Hi Beggarman, sorry for the late reply, and also just wanted to say "thank you very much." It seems like the environment variables change a bit for some reason (the variables that show up after "set" command), but it gets very close to what I was looking for. Again, thank you very much!Brout
The original response didn't pickup your csh environment - I overlooked that requirement. The updated response should fix that.Foist
Hi, thanks for the answer. Do you know how I can get this into my ssh_config on a specific host?Illegitimate
@cjohansson, I believe what you're looking for in ssh_config is the RemoteCommand option.Theo
@JFlo, in couple with RequestTTY option (-t switch).Glauconite

© 2022 - 2024 — McMap. All rights reserved.