Re: verifying a given jail is running

From: Miroslav Lachman <000.fbsd_at_quip.cz>
Date: Wed, 18 Aug 2021 17:19:22 UTC
On 18/08/2021 18:21, Dan Langille wrote:

> I could use it like this in a shell script.
> 
> jls -j freshports > /dev/null 2>&1
> if [ $? = 0 ] ; then
>    echo jail is running
> else
>    echo jail is not running
> fi
> 
> The main reason I need this: Verifying the jail is running before 
> continuing with a script.

You can save one line with this:

if jls -j freshports > /dev/null 2>&1 ; then
	echo "jail is running"
else
	echo "jail is not running"
fi

Or if you don't need the echoed output and just need to stop script 
execution:

jls -j freshports > /dev/null 2>&1 || exit 5

Miroslav Lachman

PS: Use jls -d if dying jail is also accepted as running jail (see man jls)