0

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?

Venom
  • 223
  • 2
  • 7
  • 15

1 Answers1

1
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.

hildred
  • 5,829
  • 3
  • 31
  • 43