Our solution will involve two steps.
- Pass Environment variable containing path to script you want to source to new
tcsh
instance. - Have
tcsh
source the script pointed at by this environment variable
For step 1 ssh
will run the command you specify in your default shell (the one in the destination server's /etc/passwd
) so I'll give you several solutions for this.
- If destination shell is
sh
/bash
: Connect to ssh server with command:ssh -t user@host 'export SOURCESCRIPT=/tmp/tmp.sh; exec /usr/bin/tcsh'
- If destination shell is
csh
/tcsh
: Connect to ssh server with command:ssh -t user@host 'setenv SOURCESCRIPT /tmp/tmp.sh; exec /usr/bin/tcsh'
- If you can modify the destination's ssh server config, add/modify
AcceptEnv
option in/etc/ssh/sshd_config
to allowSOURCESCRIPT
environment variable to be passed (e.g.AcceptEnv SOURCESCRIPT
), setSOURCESCRIPT
in local environment and connect with command:ssh -t -o SendEnv=SOURCESCRIPT user@host 'exec /usr/bin/tcsh'
For step 2, we modify ~/.tcshrc
to add the following:
if $?SOURCESCRIPT then source $SOURCESCRIPT endif