Looping Through Jails

by J. Edward Durrett

When working with a large number of Jails on FreeBSD, it makes sense to
automate as much as possible. The simple small script below rotates
through a list of jails, converts the jail name to a numerical jail id
and then executes the specified script:

 
#!/bin/csh 
set path_to_script =  
set NAMEJAILS =( ) 
foreach n ($NAMEJAIL) 
  set jjid = ( `jls -j $n jid` ) 
  echo $jjid 
  jexec $jjid $path_to_script 
end 

It is important to use the jail id, rather than the name, as a possible
race could occur from the time the jail is looked up and the command
gets executed inside the jail. This is documented in the manual for
jexec(8).

This simple script can be built upon, saving hours of administration
time.







Copyright (c) 2019, Jason Edward Durrett - All content on this site, unless otherwise noted, is subject to this license.

Please contact me if any errors, such as erroneous / misleading content or missing / incomplete attribution, are found.