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.


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


Answer, put it in a script 1.sh,

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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