Hello everyone.
Can you please tell me if there is a possibility to transfer the value of a variable to the command executed on the remote server via SSH:

ssh -p22 [email protected]'$RM -f $LR'code>

With this option, the remote server reads the command without assigning a value to a variable.

Thank.
  • Explain on which side you need to replace the variables with their value? – Disney's88 Nov 20 '17 at 16:08
  • Disney's88, on a remote server – Def Jam Nov 20 '17 at 16:18

1 Answers 1

ssh -p22 [email protected]"$RM -f $LR"
Substitute the local values ​​of RM and LR.

is it possible to pass the value of a variable

Only variables known in advance by the ssh server on the other side, only when using the SSH version 2 protocol.From man ssh_config:
SendEnv
             Specifies what variables from the local environ(7) should be sent to the server.Note that the environment must be supported for protocol 2.The server must also be supported.
             configured to accept these environment variables.Refer to AcceptEnv in sshd_config(5).Variables are specified by name, which may contain wildcard characters.Multiple
             environment variables may be separated by whitespace or spread across multiple SendEnv directives.The default is to send any environment variables.

But the question arises: why transfer them, if everything you need can be transferred on the command line?
  • But the question arises: why transfer them, if all you need to do can be passed on the command line?


    The value of LR is constantly changing.
    – Def Jam Nov 20 '17 at 18:37
  • [[subba]], Give a real example, because in your example nothing changes. – Ninja15 Nov 20 '17 at 20:31
  • The variable LR is assigned the name of the last file in the folder. – Def Jam Nov 20 '17 at 22:46
  • [[subba]], assigned where? On the side where ssh is called? Deploy LR on the same side and transmit on the command line.On that side? Then you don’t need to send it anywhere.

    I repeat: give a real example, so as not to theorize about anything.
    – Ninja15 Nov 20 '17 at 22:50
  • [[jcmvbkbc]],
    $SSH'cd/test1/&ls -lt | sed 1d'| awk'{print $9}'>/Temp/LR.txt
    LR=`sed -n 4p /Temp/LR.txt`
    – Def Jam Nov 21 '17 at 17:56
  • [[subba]], i.e.'cd/test1/&&ls -lt | sed 1d'is executed remotely, the output arrives on the local machine in awk'{print $9}'>/Temp/LR.txt after which the fourth line is locally placed in LR.Perfectly.This example does not need the value of the LR environment variable on the remote machine. – Ninja15 Nov 21 '17 at 18:06
  • [[jcmvbkbc]], followed by
    RM=/bin/rm
    LR=`sed -n 4p/Temp/LR.txt` #/test1/4.txt
    ssh -p22 [email protected]"$RM -f $LR"
    – Def Jam Nov 21 '17 at 18:11
  • [[subba]], fine, LR is still not needed on the remote machine, its value will be substituted into the ssh command line locally. – Ninja15 Nov 21 '17 at 18:22
  • $(here you need everything) – Small-Time41 Nov 29 '17 at 10:24