I followed this tutorial for running several commands through ssh in bash script. But now I want to get the output of one of the commands that I am running through the ssh, save it in a variable and use in the next command.
#!/bin/bash
ssh -t $VM_IP_ADDRESS bash -c "'
export NET_ID=nova network-list | egrep $SUBNET_NAME | get_field 1
nova boot $INSTANCE1_NAME --flavor m1.small --image $UBUNTU_IMAGE_NAME --key-name $KEY_PAIR_NAME --security-groups default --nic net-id=$NET_ID
'"
I want to set the NET_ID in my local environment and then use it in the next command. Now when I run this I get this error:
bash: line 17: export: `network-list': not a valid identifier
But I already checked and this command gives me the correct answer in the target machine.
nova network-list | egrep test_net | get_field 1
UPDATE:
With this command the NET_ID variable is setting in the target machine environment, but I wanted to set it in my local machin.
export NET_ID=\$(nova network-list | egrep $SUBNET_NAME | get_field 1)