SSH remote execute command with special chars

bashssh

Im trying to run this from my shell:

I have a bunch of machines, so i have this in my .bash_profile

function sssh() {
  ssh -i ~/.ssh/supersecret.pem $@
}

This is the command:

export BOX=mybox.a.domain.com
sssh www-data@$BOX "tail -n 1 /path/to/logs/some.log | awk -F '\t' '{print $1}'"

The log file is separated by tabs. Hence the -F '\t' on the awk — which is exactly the issue. Its being escaped and not showing me the column i want. When i run tail -n 1 /path/to/logs/some.log | awk -F '\t' '{print $1}' locally on the box it works as expected. How can i fix this?

Best Answer

I found the answer after some trial and error:

ssh www-data@$BOX "tail -n 1 /server/musicgraph/prod/logs/dao.log | awk -F\$'\\t' '{print \$1}'"