From owner-freebsd-stable@FreeBSD.ORG Tue Dec 18 20:26:36 2007 Return-Path: Delivered-To: stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9115016A46B for ; Tue, 18 Dec 2007 20:26:36 +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 41B4713C465 for ; Tue, 18 Dec 2007 20:26:36 +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 A947619E023; Tue, 18 Dec 2007 21:06:54 +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 9774E19E019; Tue, 18 Dec 2007 21:06:48 +0100 (CET) Message-ID: <47682873.8050601@quip.cz> Date: Tue, 18 Dec 2007 21:07:15 +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: Anton - Valqk References: <4767E08C.2090803@lozenetz.org> In-Reply-To: <4767E08C.2090803@lozenetz.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: stable@freebsd.org 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: Tue, 18 Dec 2007 20:26:36 -0000 Anton - Valqk wrote: > Because I'm lazy and love the scripts, I wrote a nice small script that > matches a jailname and do a jexec JAILPID SHELL > so I can login fast to my jails. > According to me, there should be such tool! > Hopes something like this goes to STABLE! > > here it is.... > > #!/bin/sh > loginSHELL="/bin/tcsh" > [ -z "$1" ] && echo "No jail specified." && exit 1; > jName=$1; > jID=`jls | awk '{print $1,$3}'|grep $jName|awk '{print $1}'` > jRealName=`jls | awk '{print $1,$3}'|grep $jName|awk '{print $2}'` > [ -z "$jID" ] && echo "No such jail name $jName!" && exit 1; > echo "Logging in to $jRealName" > jexec $jID $loginSHELL It is nice idea, but I think you should have a better scripting style ;) #!/bin/sh login_shell="/bin/tcsh" if [ -z "$1" ]; then echo "No jail specified." exit 1 fi jail_name=$1 jail_id=`jls | awk '$3 ~ /^'${jail_name}'\./ { print $1 }'` jail_hostname=`jls | awk '$3 ~ /^'${jail_name}'\./ { print $3 }'` if [ -z "$jail_id" ]; then echo "No such jail name ${jail_name}!" exit 1 fi echo "Logging in to ${jail_hostname}" jexec $jail_id $login_shell And still there are some imperfections. 1) script assume first part of a hostname as name, but in the rc.conf jail name can be different 2) script does not expect multiple occurrence of the same first part of a hostname example: johndoe.example.org and johndoe.comethingelse.org 3) script does not expect multiple occurrence of exactly matching hostname (coused by jail zombies) Miroslav Lachman