Re: verifying a given jail is running

From: Miroslav Lachman <000.fbsd_at_quip.cz>
Date: Wed, 18 Aug 2021 19:19:22 +0200
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)
Received on Wed Aug 18 2021 - 17:19:22 UTC

Original text of this message