Get IP from machine using CLI

Hi, I currently making a bash script to perform some tests in my setup.
I need to get the IP from a recently deployed machine to use to perform some ping and other.

How can I get the ping from the CLI? I can see it on the GUI but I want to make the script automated.

Thanks all.

I found that with this command:
maas $PROFILE interfaces read $SYSTEM_ID | jq ‘.[] | {links:.links[] |{ip:.ip_address}}’ --compact-output)

I can get an output like this:
{“links”:{“ip”:“10.10.10.38”}}

But how can I extract only the IP?

@jbacelo, try this:

maas $PROFILE interfaces read $SYSTEM_ID | jq '.[] | (.links[].ip_address)' | sed -e 's/^"//' -e 's/"$//'

which gives something like:

192.168.123.16

It worked great.
Thanks @billwear

1 Like

np. i can usually help with CLI + jq issues, feel free to ping me on discourse.

Pro-tip - to avoid the jq | sed check out jq's -r option

$ maas $PROFILE interfaces read $SYSTEM_ID | jq -r '.[] | (.links[].ip_address)'
10.245.136.62
2 Likes

yep. nice tip, thanks @sparkiegeek.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.