jlogin.sh - a small nice jails helper!
Miroslav Lachman
000.fbsd at quip.cz
Thu Dec 20 11:21:44 PST 2007
Oliver Fromme wrote:
> Miroslav Lachman wrote:
> > It is nice idea, but I think you should have a better scripting style ;)
>
> Yes, it almost looked like perl. :-)
> May I suggest a few further improvements?
>
> > login_shell="/bin/tcsh"
>
> I certainly wouldn't want tcsh. How about looking at
> $SHELL, and if it doesn't exist, then fall back to the
> standard shell (which is /bin/sh).
I have tought about optional second argument with shell name, your idea
about $SHELL is also good.
> Also, the last command (jexec) should be preceded by
> "exec" so the shell doesn't hang around. So the last
> part of the script would look like this:
>
> jail_path=$(jls | awk '$1=='$jail_id' {print $4}')
>
> if [ -z "$SHELL" -o ! -x "$jail_path/$SHELL" ]; then
> login_shell="$SHELL"
> else
> login_shell="/bin/sh"
> fi
>
> echo "Logging in to $jail_hostname"
> exec jexec $jail_id $login_shell
>
> Best regards
> Oliver
>
> PS: By the way, here's another useful script that displays
> processes running in jails, ordered by jail IDs:
>
> http://www.secnetix.de/~olli/scripts/jps
I am using your jps in slightly modified version ;)
ME="${0##*/}"
Usage()
{
cat <<-tac
$ME -- List processes that are running inside a jail.
This is intended to complement the standard jls(8) command.
Usage:
$ME list all jailed processes
$ME <JID> list only processes in jail <JID>
Run the jls(8) command to get a list of jails and JIDs.
tac
exit 1
}
if [ $# -gt 2 ]; then
Usage
fi
if [ $# -eq 1 ]; then
case "$1" in
""|*[!0-9]*) Usage ;;
esac
FILTER='$1=="'$1'"'
sum_jid="$1"
jname=`jls | awk "$FILTER"'{ print $3 }'`
else
FILTER='$1!="0"'
sum_jid="all"
jname="-"
fi
ps -axww -o jid,pid,%mem,rss,user,command | awk '$1!~/[0-9]/||'"$FILTER"
| sort -n
echo
echo "=============================="
echo " summary for JID $sum_jid / $jname"
echo " %MEM RSS VSZ %CPU "
ps -axww -o jid,%mem,rss,vsz,%cpu | awk '$1!~/[0-9]/||'"$FILTER" | awk
'{ sm += $2; sp += $3; sv += $4; sc += $5 } END { printf(" %3d %9i %9i
%3d \n", sm, sp, sv, sc) }'
#--
More information about the freebsd-stable
mailing list