[BusyBox] ash and grep with busybox 1.00

Brenda Butler bbutler at symbium.com
Mon Feb 21 16:18:19 UTC 2005


On Mon, Feb 21, 2005 at 04:12:49PM +0000, Florian Fainelli wrote:
> Hi !
> 
> I would like grep to return me only one line, it is possible to do that ? eg :
> 
>  ps aux | grep -c "/usr/sbin/telnetd"
> 1
>  ps aux | grep -c "/usr/sbin/telnetd"
> 2
> It's pretty unpredictable :) I could use sed to return me only one line, but I 

It depends how many telnetd's are running, it returns all of them.
Which one do you want?  Is the first one always sufficient?
Or perhaps grep is returning itself... it also contains
/usr/sbin/telnetd on its command line
If so:

ps aux | grep "/usr/sbin/[t]elnetd"

will find only the telnetd process and not the grep process.


ps aux | grep "/usr/sbin/[t]elnetd" | head -1

if there are still more than one telnetd and the first one
is sufficient for your purposes.

> does fit to my needs.
> 
> Then, why does ash gives me an error when attempting to do that :
> 
> if [ `ps aux | grep -c telnet` >= "1" ]; then
                                 ^^

Numeric comparison operators are:

-gt
-ge
-lt
-le

etc

> 	tel="on"
> else
> 	tel="off"
> fi
> 
> ash does not like >= operator ? Or am I wrong with the ash operators ?

But hopefully you can use the first solution above to avoid
the second one.


Hope this helps.

cheerio,
bjb



More information about the busybox mailing list