FOR/WHILE COMMAND how to halt/boot all the containers/zones with a for/while command (Solaris 10/11)
FOR COMMAND HOW TO HALT/BOOT (Containers/Zones) with a FOR command
1.- List zones / containers in running state in order to check what zones you need stop/boot after finishing the task that you perform on the global zone
# zoneadm list -v
0 global running /
1 zone1 running /zones/zone1
2 zone2 running /zones/zone2
3 zone3 running /zones/zone3
6 zone4 running /zones/zone4
7 zone5 running /zones/zone5
8 zone6 running /zones/zone6
9 zone12 running /zones/zone12
12 zone15 running /zones/zone15
14 zone16 running /zones/zone16
19 zone17 running /zones/zone17
2.- Send the zones list to a file only with the NAME of the zones to zones.txt file
#zoneadm list -v | awk '{print $2}' | egrep -v global >> zones.txt
3.- List the information capture in order to verify zones.txt
# cat zones.txt
4.- Halt Zones with a for command
# for i in `cat zones.txt`; do zoneadm -z $i halt; done
5.- Boot Zones with a for command
# for i in `cat zones.txt`; do zoneadm -z $i boot; done
If you do not want to use a for command you can use a WHILE command
1.- Halt with a while the zones running
#zoneadm list -iv | grep -v NAME | grep -v global | awk '{print $2}' | while read CONTAINERS; do zoneadm -z $CONTENEDOR halt; done
2.- Boot with a while the zones halted
#zoneadm list -iv | grep -v NAME | grep -v global | awk '{print $2}' | while read CONTAINERS; do zoneadm -z $CONTENEDOR halt; done
1.- List zones / containers in running state in order to check what zones you need stop/boot after finishing the task that you perform on the global zone
# zoneadm list -v
ID NAME STATUS PATH
0 global running /
1 zone1 running /zones/zone1
2 zone2 running /zones/zone2
3 zone3 running /zones/zone3
6 zone4 running /zones/zone4
7 zone5 running /zones/zone5
8 zone6 running /zones/zone6
9 zone12 running /zones/zone12
12 zone15 running /zones/zone15
14 zone16 running /zones/zone16
19 zone17 running /zones/zone17
2.- Send the zones list to a file only with the NAME of the zones to zones.txt file
#zoneadm list -v | awk '{print $2}' | egrep -v global >> zones.txt
3.- List the information capture in order to verify zones.txt
# cat zones.txt
4.- Halt Zones with a for command
# for i in `cat zones.txt`; do zoneadm -z $i halt; done
5.- Boot Zones with a for command
# for i in `cat zones.txt`; do zoneadm -z $i boot; done
If you do not want to use a for command you can use a WHILE command
1.- Halt with a while the zones running
#zoneadm list -iv | grep -v NAME | grep -v global | awk '{print $2}' | while read CONTAINERS; do zoneadm -z $CONTENEDOR halt; done
2.- Boot with a while the zones halted
#zoneadm list -iv | grep -v NAME | grep -v global | awk '{print $2}' | while read CONTAINERS; do zoneadm -z $CONTENEDOR halt; done
Comments