1

This won't run,

ssh -o ConnectTimeout=10 -o BatchMode=yes -o "StrictHostKeyChecking no" -q server1  "if [[ $(/usr/bin/lsblk /dev/sde | wc -l) = 2 ]]; then echo found; fi"

But if I do it on the remote cli or using ansible "if [[ $(/usr/bin/lsblk /dev/sde | wc -l) = 2 ]]; then echo found; fi", it will run. I don't want to use ansible all the time since we only have tower and slow to do simple query.

Thanks for your support.

Gordon Davisson
  • 11,216
  • 4
  • 28
  • 33
Ricky Vene
  • 21
  • 1
  • 1
  • 4

2 Answers2

2

The command substitution $(/usr/bin/lsblk ... ) is in double-quotes and the $ is not escaped, so it'll be executed and substituted on the local computer before ssh is even executed. If you want that to be run on the remote system, either use single-quotes instead of double, or escape the $.

Gordon Davisson
  • 11,216
  • 4
  • 28
  • 33
0

Answer, put it in a script 1.sh,

ssh -o ConnectTimeout=10 -o BatchMode=yes -o "StrictHostKeyChecking no" -q server < 1.sh

Ricky Vene
  • 21
  • 1
  • 1
  • 4