From owner-freebsd-questions@FreeBSD.ORG Sun Aug 21 19:27:58 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2DC9516A420 for ; Sun, 21 Aug 2005 19:27:57 +0000 (GMT) (envelope-from freebsd@nagilum.org) Received: from p15140542.pureserver.info (papendorf-se.de [217.160.222.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0223243D49 for ; Sun, 21 Aug 2005 19:27:56 +0000 (GMT) (envelope-from freebsd@nagilum.org) Received: from localhost (localhost.localdomain [127.0.0.1]) by p15140542.pureserver.info (Postfix) with ESMTP id B38F02F4119; Sun, 21 Aug 2005 21:27:54 +0200 (CEST) Received: from p15140542.pureserver.info ([127.0.0.1]) by localhost (p15140542 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 10378-20; Sun, 21 Aug 2005 21:27:53 +0200 (CEST) Received: from cakebox.homeunix.net (e180045018.adsl.alicedsl.de [85.180.45.18]) (using TLSv1 with cipher EDH-RSA-DES-CBC3-SHA (168/168 bits)) (No client certificate requested) by p15140542.pureserver.info (Postfix) with ESMTP id E13492F4117; Sun, 21 Aug 2005 21:27:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by cakebox.homeunix.net (Postfix) with ESMTP id B1A2D3028AC; Sun, 21 Aug 2005 21:27:51 +0200 (CEST) Received: from cakebox.homeunix.net ([127.0.0.1]) by localhost (cakebox.tis [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 87533-07; Sun, 21 Aug 2005 21:26:58 +0200 (CEST) Received: from [10.1.1.4] (unknown [10.1.1.4]) by cakebox.homeunix.net (Postfix) with ESMTP id D2C50302864; Sun, 21 Aug 2005 21:26:34 +0200 (CEST) Message-ID: <4308D561.6090102@nagilum.org> Date: Sun, 21 Aug 2005 21:26:25 +0200 From: Nagilum User-Agent: Mozilla Thunderbird 1.0.2 (Macintosh/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: virtual@virtualgod.net References: <3463.82.77.180.238.1123272728.squirrel@virtualgod.net> In-Reply-To: <3463.82.77.180.238.1123272728.squirrel@virtualgod.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at cakebox.homeunix.net X-Virus-Scanned: amavisd-new at papendorf-se.de Cc: freebsd-questions@freebsd.org Subject: Re: bash script X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Aug 2005 19:27:58 -0000 virtual@virtualgod.net wrote: >My knowledge in bash scripting is about medium not very advanced and all >so I am not attempting to make a connection limiter but what I want to >make is a script that checks the irc connections off a certain user and >takes some actions, mostly of this I know how to do but I got stuck at >this : >I write in a file we will call it users.allow the following: >Virtual 5 >Test 7 >Server 9 >Power 2 > >This will be the file that will hold the limit of the users from where the >script reads when checks. >So my script will read from this file and if the user Virtual for example >has more than 5 connections he will kill all his processes that are >running in background. >But what what I don`t know how to do is make the script read, for example >if I start the script he starts reading from users.allow, I want it to >read an take each line, first taking the line 1 with user Virtual and >setting to a variable the number it has near it like $allow=5, next after >it finishes the process for Virtual takes Test etc. >So my need would be how can I get the script to read first line, do the >process I will make for it, then take the next line and do the process for >that user until end of file. And also after taking the first line for >example reading only the first block in it, the one with user so it can >set $user=Virtual and then to take the path with the number. >I would greatly apreciate if you can help me with this issue, I really >need this script but didn`t know what to look in the manuals for etc. >Also if you know a similar script please let me know. > > Well, you could either use a counter: file=$0 count=`expr 1` lines=`wc -l <$file` while [ $count -le $lines ]; do line=`sed -n ${count}p` $file echo $line count=`expr $count + 1` done; for a very slow version of cat ;) or you could simply grep for the line you need line=`grep "Power" $file` I hope this helps..