Skip to content

Are we running in a zone?

February 27, 2012

Theres a few ways to tell if the solaris server you’re running on is a zone. My preferable method is to zoneadm list and see if it returns the global zone.

# zoneadm list -cv
  ID NAME             STATUS     PATH          BRAND    IP
   0 global           running    /             native   shared
#!/bin/bash

zonecount () {
# Return 0 if we're a non-global zone.
# Otherwise return the count of number of
# installed non global zones +1

  list=( `/usr/sbin/zoneadm list -pi` )

  global=(`echo ${list[0]} | cut -d: -f2`)

  if [ $global != "global" ]; then
  # This is a non-global zone
    return 0

  else
  # Number of items in array = number of zones
    return ${#list[@]}
  fi

  }

zonecount

ZC=$?

if [ ${ZC} -eq 0 ]; then
  echo "Non-global zone"
  # Do some stuff you only want to do if its a non-global zone.
else
  echo "Global zone with `(echo "${ZC} - 1" | bc)` running or installed non-global zones"
  # Do some stuff you only want to do in the global zone.
fi
Advertisements

From → Scripts, SysAdmin

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: