I need to append a line of text to a file on a remote machine where the directory path contains it's hostname. I need to do this on multiple systems, so I need to be able to discover the hostname on each one.
ssh user@server "echo $line >> /dir1/dir2/$HOSTNAME/destination file"
if I single quote my command it does not expand my $line variable before it runs it, if I double quote it it expands $HOSTNAME locally.
How can I pass my local $line variable to ssh and still have it evaluate $HOSTNAME correctly?