Skip to content

Instantly share code, notes, and snippets.

@Sp1l
Last active October 15, 2015 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sp1l/4da6ca216b61349a542d to your computer and use it in GitHub Desktop.
Save Sp1l/4da6ca216b61349a542d to your computer and use it in GitHub Desktop.
#!/bin/sh
# set -x
[ `id -u` -ne 0 ] && { echo Not root... exiting... ; exit 1 ; }
runJExec () {
# JailID is the first column
local jid jname rc
jid=${line%% *}
# JailName is the first part of the third column
jname=${line#* } # Remove first column
jname=${jname#* } # Remove second column
jname=${jname%%.*} # Remove everything after first dot
# Check if the jailname exists
if [ "${jname}" = "$1" -o "$1" = "all" ] ; then
if [ "$1" = "all" -a -z "$silent" ] ; then
echo Jail: $jname
fi
shift
jexec $jid $@
rc=$?
return $rc
else
echo "Jail ""$1"" not started or unknown" >2
exit 1
fi
echo $*
}
if [ $# -le 1 ] ; then
cat <<EOT
Execute a command in a jail by name
Usage: ${0##*/} [-s] <jailname>|all <command>
-s : silent
EOT
exit 0
fi
if [ "$1" = "-s" ] ; then
silent=YES
shift
fi
if [ "$1" = "all" ] ; then
IFS='
'
rcall=0
for line in `jls | sed -E '/JID IP Address Hostname/d;s/[[:space:]] */ /g;s/^ //'` ; do
runJExec $@
rc=$?
if [ $rc -gt $rcall ] ; then rcall=$rc ; fi
done
exit $rcall
else
# Get the jail details using jls
line=`jls | sed -E '/'$1'/!d;s/[[:space:]] */ /g;s/^ //'`
runJExec $@
exit $?
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment