Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by Gilles May 5 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.

1 Answer 1

up vote 1 down vote accepted
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.

share|improve this answer

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