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:

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:

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)'

yep. nice tip, thanks @sparkiegeek.

1 Like

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