Ssh – Appending a string to a file from remote ssh

echosshtext processing

I want to ssh to a node (which is passwordless) and append $spool_as_final_name true to a file /var/spool/torque/mom_priv/config. Note that is mandatory to put $ in front of the string.

So, I wrote

ssh node01 "echo \"\$spool_as_final_name true\" >> /var/spool/torque/mom_priv/config" 

However the file looks like

Dummy
 true

I intentionally wrote Dummy to show you that true is written in the second column.

How can I fix that?

Best Answer

Simply use,

ssh node1 'echo "\$spool_as_final_name true" >> /var/spool/torque/mom_priv/config'

Or you can use the cat command,

echo "\$spool_as_final_name true" | ssh node1 "cat >> /var/spool/torque/mom_priv/config"
Related Question