jlogin.sh - a small nice jails helper!
Anton - Valqk
lists at lozenetz.org
Sat Dec 22 03:32:32 PST 2007
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.
More information about the freebsd-stable
mailing list