I want to run a remote command over ssh. So, the one line command is
ssh [email protected] 'VMID=`./run_prog` && if [ -n $VMID ]; then echo "id=$VMID"; vim-cmd vmsvc/power.off $VMID; else echo "$VMID empty"; fi'
Problem is that if VMID
is empty or non-empty, I see the output of vim-cmd
.
id=
Usage: power.off vmid
or
34
Powering off VM:
How can I be sure that vim-cmd
is executed for non-empty VMID
values?
VMID empty
to be output? Would the lack of any other output be sufficient to indicate that it was empty?run_prog
have a non-zero exit status if it fails to produce any output? You could test that instead of explicitly checking the contents of the variable.VMID=$(./run_prog) && vim-cmd vmsvc/power.off "$VIMD"
.