I need to get the oldest instance from an instance group. I am using the following command:
gcloud compute instance-groups managed list-instances "instance-group-name" --region "us-central1" --format="value(NAME,ZONE,CREATION_TIMESTAMP)" --sort-by='~CREATION_TIMESTAMP'
But it seems --sort-by is not working or I am using it a bit wrong.
Could you please suggest the right way.
It's probably creationTimestamp
not CREATION_TIMESTAMP
.
See: instances.list and the response body for the underlying field names.
It's slightly confusing but gcloud
requires you to use the (field|property) names of the underlying request|response types not the output names.
Another way to more readily determine this is to add --format=yaml
or --format=json
to gcloud compute instances list
(or any gcloud
command) to get an idea of what's being returned so that you can begin filtering and formatting it.