Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Dec 2007 13:07:19 +0200
From:      Anton - Valqk <lists@lozenetz.org>
To:        freebsd-stable@FreeBSD.ORG,  000.fbsd@quip.cz,  lists@lozenetz.org
Subject:   Re: jlogin.sh - a small nice jails helper!
Message-ID:  <476CEFE7.3060402@lozenetz.org>
In-Reply-To: <200712201741.lBKHfDRb069152@lurza.secnetix.de>
References:  <200712201741.lBKHfDRb069152@lurza.secnetix.de>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi there,
your script didn't had what I wanted for the ps, that's why I wrote
simpler one for myself,
that's do the job for me - finds a string from ps axu from any jail :)

here it is, hopes it's useful (quick 15mins hack script).

#!/bin/sh
#list all jails processes
#$1 - jid - jail pattern || ALL
#$2 - string in jail ps axu cmd

if [ -n "$2" ]; then
        psFilter="grep $2"
fi
if [ -n "$1" ] && [ "$1" != "ALL" ]; then
        jName=$1
        jID=`jls | grep $jName|awk '{print $1}'`
        jRealName=`jls |grep $jName|awk '{print $3}'`
        echo "Listing processes for $jRealName ( $jID )..."
        if [ -n "$psFilter" ]; then
                jexec $jID ps axu|$psFilter
        else
                jexec $jID ps axu
        fi
else
        for jID in `jls|awk '{print $1}'`;
        do
                if [ "$jID" -gt 0 ]; then
                jRealName=`jls|grep $jID|awk '{print $3}'`
                echo "Listing processes for $jRealName ( $jID )..."
                if [ -n "$psFilter" ]; then
                        jexec $jID ps axu|$psFilter
                else
                        jexec $jID ps axu
                fi
                fi
        done
fi




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).
>
> 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
>
>   


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?476CEFE7.3060402>