From owner-freebsd-stable@FreeBSD.ORG Thu Dec 20 19:21:44 2007 Return-Path: Delivered-To: freebsd-stable@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E32316A419 for ; Thu, 20 Dec 2007 19:21:44 +0000 (UTC) (envelope-from 000.fbsd@quip.cz) Received: from elsa.codelab.cz (elsa.codelab.cz [82.208.36.70]) by mx1.freebsd.org (Postfix) with ESMTP id 3314E13C4E3 for ; Thu, 20 Dec 2007 19:21:43 +0000 (UTC) (envelope-from 000.fbsd@quip.cz) Received: from localhost (localhost.codelab.cz [127.0.0.1]) by elsa.codelab.cz (Postfix) with ESMTP id B55AD19E023 for ; Thu, 20 Dec 2007 20:21:42 +0100 (CET) Received: from [192.168.1.2] (r3a200.net.upc.cz [213.220.192.200]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by elsa.codelab.cz (Postfix) with ESMTP id 03B7719E019 for ; Thu, 20 Dec 2007 20:21:30 +0100 (CET) Message-ID: <476AC0D7.7090402@quip.cz> Date: Thu, 20 Dec 2007 20:21:59 +0100 From: Miroslav Lachman <000.fbsd@quip.cz> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: cz, cs, en, en-us MIME-Version: 1.0 To: freebsd-stable@FreeBSD.ORG References: <200712201741.lBKHfDRb069152@lurza.secnetix.de> In-Reply-To: <200712201741.lBKHfDRb069152@lurza.secnetix.de> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Re: jlogin.sh - a small nice jails helper! X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Dec 2007 19:21:44 -0000 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 list only processes in jail 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) }' #--