0

I have a custom profile script on a remote host. I'd like to source it when I connect to the host automatically. I cannot change anything on the remote host. Things I've tried but didn't work:

ssh -t myhost '. /local/scratch/scripts/rtc_profile ; bash -l'
ssh -t myhost 'bash -l /local/scratch/scripts/rtc_profile'

I've also tried the following (which works), but it skips all other rcfiles:

ssh -t myhost 'bash --rcfile /local/scratch/scripts/rtc_profile '

Please help :)

Maxim_united
  • 1,911
  • 1
  • 14
  • 23
  • Why not just have your `rtc_profile` file source the normal `.bashrc` file at the end and use `--rcfile`? – Etan Reisner Jul 30 '14 at 16:22
  • Thought of this, but is .bashrc is the only rcfile by default? – Maxim_united Jul 30 '14 at 16:26
  • From the man page: "--rcfile file - Execute commands from file instead of the standard personal initialization file ~/.bashrc if the shell is interactive". What your bashrc file loads in addition to that is something else. Read the `INVOCATION` section of the bash man page for the full startup file details. – Etan Reisner Jul 30 '14 at 16:32
  • Well, ~/.bashrc apparently doesn't exist on the host. ~/.bash_profile does. So I can source that one, but I fear I might miss out on any other rc files. – Maxim_united Jul 30 '14 at 16:44
  • `.bashrc` and `.bash_profile` are sourced for different types of shells. Read the `INVOCATION` section. It is somewhat complicated. Though the short version is if you don't have a `$HOME/.bashrc` file then `--rcfile` can't hurt you. – Etan Reisner Jul 30 '14 at 16:45

1 Answers1

0

You can put the following at the end of your ~/.bashrc:

if [ ! -z "$SSH_CONNECTION" ] ; then
    source /local/scratch/scripts/rtc_profile
fi
hek2mgl
  • 152,036
  • 28
  • 249
  • 266