Running a custom profile file on remote host

2019-06-12 21:06发布

问题:

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 :)

回答1:

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

if [ ! -z "$SSH_CONNECTION" ] ; then
    source /local/scratch/scripts/rtc_profile
fi


标签: bash ssh