• Script to Determine Solaris 10 Zone Type

    We use a lot of local zones in our Solaris 10 environment. We also use cfengine pretty heavily and there are some instances when we need to include or exclude certain automated tasks based on what type of zone we are working with. I wrote this little script that checks to see what type of zone we are dealing with. Based on the return value, I can set a cfengine class and control what gets run and where.

    • Return 0 if the machine is a global zone with 1 or more local zones
    • Return 1 if the machine is either a local zone or a global zone with 0 local zones
    #! /bin/bash
    #
    # When issued with the -g or --global flag, this script will return:
    # 0 if the machine is a global zone and has one or more local zones.
    # Otherwise, it will return 1
    #
    # Wen issued with the -l or --local flag, this script will return:
    # 0 if if is a local zone and 1 if it is not
    #
    
    list=( `/usr/sbin/zoneadm list -civ | awk '{ print $1 }'`)
      case "$1" in
        -g|--global)
            # If the third element in our array is null, set it to 0
            if [ "${list[2]}" == ""  ]; then
            list[2]=0
            fi
            # This is a global zone only if it has one or more local zones.
            if [ ${list[1]} -eq 0 ] && [ ${list[2]} -ge 1 ]; then
            # 1 is returned if we have a global and local zone, otherwise, we return 0
                    exit 0
                else
                    exit 1
            fi
                  ;;
        -l|--local)
            # If the second element in our array is = or > 1, it is a local zone.
            if [ ${list[1]} -ge 1 ]; then
            # Return 1 if this is a local zone, otherwise return 0.
                    exit 0
                else
                    exit 1
            fi
                  ;;
            *)
            echo "Usage: /local/adm/zonetype.sh {-l | --local | -g | --global}"
            exit 1
      esac
    
    This entry was posted on Tuesday, March 3rd, 2009 at 6:46 pm and is filed under Data and Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 3 Comments

    Take a look at some of the responses we've had to this article.

    1. I love using UNIX because there are so many ways to do the same thing.

      My tip for finding if I’m in a local zone or global is to look at the init process id.

      Global zone id = 1
      Local zone != 1

      Andy

    2. Thanks for the tip. Here is another way to skin this cat:

      [ `/usr/bin/zonename` = "global" ] && exit 0 || exit 1

      Juan

    3. [...] Script to Determine Solaris 10 Zone TypeSolaris X86 Compatible RAID ControllerInstall Solaris Package in Alternate Base Directory [...]

  • Leave a Reply

    Let us know what you thought.

  • Name (required):

    Email (required):

    Website:

    Message:

Visitors have tagged this post: solaris 10 zones (26) - solaris zone commands (18) - solaris zones howto (13) - solaris containers zones (13) - solaris 10 zone (12) - how to check global zone from local zone (12) - solaris zone type (10) - zoneadm commands (10) - how to find global zone from local zone (10) - solaris zone create script (9) - global zone solaris 10 (8) - Solaris 10 scripts (7) - solaris script (7) - solaris 10 zone commands (7) - determine global zone (6) - solaris 10 global zone (6) - zoning in solaris (6) - local (6) - solaris zones (6) - commands to list global zone name in solaris (6) - solaris scripts (5) - solaris 10 startup scripts (5) - Zones in Solaris 10 (5) - zoneadm (5) - determine global zone solaris (5) - solaris zones commands (5) - script solaris (4) - solaris 10 zone type (4) - solaris zone types (4) - solaris 10 zoning (4) - solaris find global zone (4) - how to determine solaris global zone (4) - how to create zone in solaris 10 (4) - zoneadm script (4) - solaris 10 zones containers (4) - zoneadm howto (4) - create zone script (4) - solaris zones types (4) - solaris 10 zones commands (4) - solaris zone determine global zone (4) - find global zone name from local zone (4) - create zone solaris 10 (4) - script container solaris (4) - script creating a solaris zone (4) - zone commands in solaris (4) - solaris determine global zone (4) - how to determine solaris zone (4) - solaris zone (3) - check duplex solaris 10 (3) - solaris zone script (3) - script solaris 10 (3) - solaris zoneadm (3) - how to determine global zone (3) - local zone solaris (3) - solaris 10 setting locale (3) - solaris 10 locale (3) - create zone solaris (3) - solaris zone creation script (3) - zone create script (3) - Find global zone Solaris 10 (3) - how to check zones on solaris (3) - how to create zone on solaris 10 (3) - scripting in solaris 10 (3) - solaris local zone (3) - solaris zones script (3) - types of solaris zones (3) - zoneadm list (3) - how to check solaris containers (3) - solaris zone howto (3) - determine zone type (3) - /local/adm/zonetype.sh (3) - types of zones in solaris (3) - Solaris determine zone type (3) - solaris how to know if we are running inside a zone? (3) - solaris container scripts (3) - solaris 10 zones howto (3) - global zone solaris (3) - creating zones in solaris 10 (3) - solaris how to tell if zones (3) - cfengine 3 solaris (3) - solaris local zone info (3) - zone creation in solaris 10 (3) - how to find zone type (3) - types of zones in solaris 10 (3) - solaris zone check (3) - cfengine 10 (3) - sun solaris zoning (3) - solaris 10 zone scripts (2) - determine zone (2) - cfengine on solaris10 (2) - determine Solaris Global zone (2) - solaris 10 list zones (2) - setting cfengine class from script (2) - determine global or local zone (2) - solaris 10 zoneadm (2) - solaris zone scripts (2) - zones script solaris (2) - booting a local zone (2) - determine solaris zone (2) - zone startup script (2) - types of solaris zones solaris 10 (2) - solaris get global zone from local zone (2) - solaris zone find global (2) - solaris container script (2) - TYPES OF SOLARIS (2) - zoning sun solaris 10 (2) - what type of solaris 10 zone (2) - solaris 10 zone script (2) - how to identify zone type (2) - how to find global zone solaris (2) - zoning sun solaris (2) - solaris global zone (2) - zone in solaris 10 (2) - global zone info from local zone solaris 10 (2) - how to know current zone solaris (2) - solaris container setup script (2) - how to determine zone solaris (2) - determine machine name in local zone (2) - list global zone solaris (2) - how to check duplex status in solaris-10 (2) - how to create a zone in solaris 10 (2) - solaris named script (2) - solaris create a zone (2) - script to create zone (2) - solaris zone info commands \"from zone\ (2) - solaris 10 scripting (2) - command to identify global and local zone in Sun containers (2) - zoning and containers solaris 10 (2) - Solaris machine name (2) - Solaris 10 script list local users (2) - how to determine solaris update (2) - how to check zones in Solaris (2) - how to check zone in solaris (2) - solaris check zone (2) - global zones solaris 10 (2) - solaris 10 zoneadm commands (2) - determine solaris OS (2) - how can I tell if a server is a zone (2) - sun solaris 10 change virtual zone locale (2) - how to check the global zone name from local zone (2) - solaris 10 find global zone (2) - solaris zone details (2) - check zone solaris (2) - zone solaris 10 (2) - how to create zone in solaris (2) - solaris10 zone types (2) - automated scripts in solaris 10 (2) - booting local zone from global zone (2) - how to see if a host is a solaris container (2) - startup script solaris 10 (2) -