Reputation: 493
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.
Upvotes: 23
Views: 35023
Reputation: 896
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 runbash -l
will start an interactive login shellcsh -l -c
will start an interactive login shell in csh, and then execute the command that followsTo 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"'
Upvotes: 33