Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Aug 2005 21:26:25 +0200
From:      Nagilum <freebsd@nagilum.org>
To:        virtual@virtualgod.net
Cc:        freebsd-questions@freebsd.org
Subject:   Re: bash script
Message-ID:  <4308D561.6090102@nagilum.org>
In-Reply-To: <3463.82.77.180.238.1123272728.squirrel@virtualgod.net>
References:  <3463.82.77.180.238.1123272728.squirrel@virtualgod.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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..




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4308D561.6090102>