I run a command to fetch server uptime as below

[root@localhosts ~]# printf "`uname -n`  `uptime| awk -F " " {'print $3,$4'}`\n"  
localhosts  75 days,

Now when I run same command from another hosts to same above linux server "localhosts" to get same output, I get error

[root@master /]# ssh localhosts 'printf "`uname -n`  `uptime| awk -F " " {'print $3,$4'}`\n"'  
awk: cmd. line:1: {print  
awk: cmd. line:1:       ^ unexpected newline or end of string  

Do you know better way to run the command from another hosts to get similar output from the remote hosts as well?

marked as duplicate by Gilles command-line May 5 '15 at 23:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

ssh localhosts 'printf "`uname -n`  `uptime| awk -F " " {'\''print $3,$4'\''}`\n"'

The issue is that you had nested single quotes. That does not work well.

Not the answer you're looking for? Browse other questions tagged or ask your own question.