我正在使用vultr-cli编写一个过程。我需要在 Vultr 部署一个新的 VPS,执行一些中间步骤,然后在 bash 脚本中销毁 VPS。部署后如何在脚本中检索实例值?有没有办法将信息捕获为 JSON 或直接设置环境变量?
到目前为止,我的脚本如下所示:
#!/bin/bash
## Create an instance. How do I retrieve the instance ID
## for use later in the script?
vultr-cli instance create --plan vc2-1c-1gb --os 387 --region ewr
## With the instance ID, retrieve the main IPv4 address.
## Note: I only want the main IP, but there may be multiple.
vultr-cli instance ipv4 list $INSTANCE_ID
## Perform some tasks here with the IPv4. Assuming I created
## the instance with my SSH key, for example:
scp root@$INSTANCE_IPv4:/var/log/logfile.log ./logfile.log
## Destroy the instance.
vultr-cli instance delete $INSTANCE_ID