I need help in determining why I get
syntax error near unexpected token `then'
from the following command:
for vm in {20..30} ; do ssh -q -o "StrictHostKeyChecking no" 192.168.210.${vm} "hostname; echo $password | su - root -c \"\ if $(whoami | grep -q root);then echo Good; else echo Bad;fi \"" ; done
vm201scf001
-bash: -c: line 0: syntax error near unexpected token `then'
-bash: -c: line 0: `\ if ;then echo Good; else echo Bad;fi '
This simple command does work though:
for vm in {20..30} ; do ssh -q -o "StrictHostKeyChecking no" 192.168.210.${vm} "hostname; echo $password | su - root -c \"\uptime \"" ; done
vm201scf001
22:11:41 up 422 days, 3:32, 0 users, load average: 0.28, 0.44, 0.52
Does the if, then, fi statement not work in this case? Please advise.