Question

A shell script installs and configures some services and applications in a Solaris instance. One of these services is NTP - but NTP cannot run in a non-global zone (well it can, but xntpd fails when it tries to adjust the clock; instead the zone inherits the time from the global zone).

How can a shell script tell that it is indeed running in a non-global Solaris zone, so that it can skip the NTP configuration step in those cases?

Was it helpful?

Solution

Use zonename(1). In the global zone (or on a standalone server without any zones), this will return the string global.

NAME
   zonename - print name of current zone

SYNOPSIS
   zonename

DESCRIPTION
   The zonename utility prints the name of the current zone.

...

OTHER TIPS

You could also try zoneadm list -cv, in the global zone you will see output like:

# zoneadm list -cv
ID NAME             STATUS         PATH
0 global           running        /
1 zone1            running        /zones/zone1

whereas in any other zone you would only see that particular zone, e.g.

# zoneadm list -cv
ID NAME             STATUS         PATH
1 zone1            running        /zones/zone1

Well, if you are running script inside zone and wanting to make sure it is running on zone then run below command

arp -a |grep SP

You can see your global zone in 1 line at output of above command. It might be useful to apply check in your script on base of this output.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top