I'm trying to work out how to get SSH to run a script before passing a shell to me. The reason for this is that I will be logging into shared users on many boxes and I want my own configuration when I log in. It would not be appropriate to put my own environment variables and aliases into .cshrc, not least because of the number of different users on different boxes that I will be logging in to.

So let's say I have my script with various alias and setenv commands at /home/adam/my_script and I want it to be sourced when I log in.

I've tried using:

ssh user@server1 'source /home/adam/my_script; tcsh'
ssh user@server1 '. /home/adam/my_script; tcsh'

and also this:

ssh user@server1 /home/adam/my_script
ssh user@server1 'csh -c /home/adam/my_script'

when tcsh (without an ampersand) is at the bottom of my_script, but no combination works as you expect. Either the environment variables and aliases don't exist, or the shell will behave strangely, like there is no line input prompt.

What am I doing wrong?

  • 2
    I would think this should work: ssh -t user@server1 'source /home/adam/my_script; tcsh' -- add -t – glenn jackman Dec 9 '14 at 16:12
  • The environment variables work but it appears that the aliases don't. I guess they're not inherited by child shells? – Doddy Dec 9 '14 at 16:24
  • You'd have to check your tcsh man page. What I do in a similar situation is edit the .bashrc to add a function that sources my config script. So I log in, type jackman and I'm set up. – glenn jackman Dec 9 '14 at 16:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.