Hi trying to create a bash script that creates a droplet, then once created gets the IP address of that droplet and store it as a variable to I used that IP address throughout the remaining bash script.
Any pointers on getting the IP and storing as a variable would be very much appreciated.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Hello,
You could do something like this:
Update the details accordingly.
The response that you would get would look something like this:
From here we could grab the Droplet ID with the
jq
command. Make sure that you havejq
installed:We could select the Droplet ID only from the output above and store it in a variable:
Then we could use the Droplet ID and with another request get the Droplet’s IP address:
The output of the curl command would look something like this:
Again with the
jq
command we could select the IPv4 address only:The whole script would look something like this:
The output that you would see at the end would look something like this:
Of course, feel free to enchant the script. Hope that this helps! Regards, Bobby