How to do some work in each active jail (FreeBSD7)

To execute set of commands inside each active jail you can use shell script:

#!/bin/sh

jails=`ezjail-admin list | grep -v "^STA" | grep -v "N/A" | grep -v "^\-" | awk '{ print $4}'`
for jail in $jails; do
   ezjail-admin console $jail  << COMMANDS
   # do something inside jail
   cd /var/mail/ && ls
COMMANDS
done

To mount port tree inside each active jail execute shell script:

#!/bin/sh

ports_dir="/home/jails/general/ports"
jails=`ezjail-admin list | grep -v "^STA" | grep -v "N/A" | grep -v "^\-" | awk '{ print $5}'`
for jail in $jails; do
  # start mess here
  mount_nullfs ${ports_dir} ${jail}/usr/ports
done
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu