Below is an example of a ssh script using a heredoc (the actual script is more complex). Is it possible to use both local and remote variables within an SSH heredoc or command?
FILE_NAME
is set on the local server to be used on the remote server. REMOTE_PID
is set when running on the remote server to be used on local server. FILE_NAME
is recognised in script. REMOTE_PID
is not set.
If EOF
is changed to 'EOF'
, then REMOTE_PID
is set and `FILE_NAME is not. I don't understand why this is?
Is there a way in which both REMOTE_PID
and FILE_NAME
can be recognised?
Version 2 of bash being used. The default remote login is cshell, local script is to be bash.
FILE_NAME=/example/pdi.dat
ssh user@host bash << EOF
# run script with output...
REMOTE_PID=$(cat $FILE_NAME)
echo $REMOTE_PID
EOF
echo $REMOTE_PID
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…