I'm trying to redirect content of a variable to a file through ssh. like:
ssh $MachineIP echo $CM_Config > $mName/CM_CONFIG
where $CM_Config
is a local variable in my host containing multiple line, and $mName/CM_CONFIG
is located in $MachineIP
how should I redirect local variable to the remote file assuming my ssh configurations are correct.
Thanks in advance
You must quote the whole command with double quotes
ssh $MachineIP "echo $CM_Config > $mName/CM_CONFIG"
This allows the variables to be replaced by the local shell and the redirection done at the remote host.
In my case the problem solved with this command:
ssh $MachineIP " echo \"$CM_Config\" > \"$mName/CM_CONFIG\" "
In fact without \" enclosing my variable, my problem didn't solved. Maybe it is because that the content of these variables are somehow like bash command and are in multiple lines.