Re: problem with shell script

2011-01-13 Thread Devin Teske
On Thu, 2011-01-13 at 14:45 -0600, Robert Bonomi wrote:
> > Date: Wed, 12 Jan 2011 15:01:45 +0100
> > From: Frank Bonnet 
> > Subject: problem with shell script
> >
> > Hello
> >
> > I'm in trouble with a simple shell script that give erroneous value when 
> > running ...
> >
> > If I run commands interactively everything runs well
> >
> >  > ps ax | grep slapd | grep -v grep | wc -l
> >1
> >
> > If I run in the following shell script :
> >
> > #!/bin/sh
> > SD=0 SD=`ps -ax | grep slapd | grep -v grep | wc -l` echo $SD
> >
> > the result is 3 !!!
> 
> Advice: don't try to 'out-think' the machine -- make it _show_ you what it
>  is doing.

Might I suggest the oft-overlooked "o" option to ps(1)...

ps axo ucomm | grep -c slapd

I can't think of anything better to achieve what the OP wanted.

Naturally... for those that need more (that is, if you want to see
meaningful output rather than just the line-count)...

try:

ps axo pid,state,ucomm

or:

ps axo pid,command | awk '$2~/slapd/{print}'

naturally, for ``wider'' output:

ps axwwwo pid,command | awk '$2~/slapd/{print}'

And the creme-de-la-creme:

ps axwwwo pid,command | awk '$2~"^slapd$"||$2~"/slapd$"{print}'

which will only print a line if the first word of the entire command is
wholly "slapd" or ends in "/slapd".

Additional solutions/combinations left as an exercise to the reader.
--
Devin

(full sig at bottom)


> 
> Change the script to:
>SD=`ps -ax | grep slapd | grep -v grep | tee /dev/tty | wc -l` echo $SD
> 
> 
> I suspect thet the -name- of the script file has 'slapd' in it.
> 
> 
> 
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"
-- 
Cheers,
Devin Teske

-> CONTACT INFORMATION <-
Business Solutions Consultant II
FIS - fisglobal.com
510-735-5650 Mobile
510-621-2038 Office
510-621-2020 Office Fax
909-477-4578 Home/Fax
devin.te...@fisglobal.com

-> LEGAL DISCLAIMER <-
This message  contains confidential  and proprietary  information
of the sender,  and is intended only for the person(s) to whom it
is addressed. Any use, distribution, copying or disclosure by any
other person  is strictly prohibited.  If you have  received this
message in error,  please notify  the e-mail sender  immediately,
and delete the original message without making a copy.

-> FUN STUFF <-
-BEGIN GEEK CODE BLOCK-
Version 3.1
GAT/CS d(+) s: a- C++() UB$ P++() L++() !E--- W++ N? o? K- w O
M+ V- PS+ PE Y+ PGP- t(+) 5? X+(++) R>++ tv(+) b+(++) DI+(++) D(+) G+>++ e>+ h
r>++ y+ 
--END GEEK CODE BLOCK--
http://www.geekcode.com/

-> END TRANSMISSION <-

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-13 Thread Robert Bonomi

> Date: Wed, 12 Jan 2011 15:01:45 +0100
> From: Frank Bonnet 
> Subject: problem with shell script
>
> Hello
>
> I'm in trouble with a simple shell script that give erroneous value when 
> running ...
>
> If I run commands interactively everything runs well
>
>  > ps ax | grep slapd | grep -v grep | wc -l
>1
>
> If I run in the following shell script :
>
> #!/bin/sh
> SD=0 SD=`ps -ax | grep slapd | grep -v grep | wc -l` echo $SD
>
> the result is 3 !!!

Advice: don't try to 'out-think' the machine -- make it _show_ you what it
 is doing.

Change the script to:
   SD=`ps -ax | grep slapd | grep -v grep | tee /dev/tty | wc -l` echo $SD


I suspect thet the -name- of the script file has 'slapd' in it.



___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-13 Thread Samuel Martín Moro
??

as already answered:
ps ax | awk '/[/]slapd /{n++} END{print n}'
searching '[s]lapd' will avoid grep "auto-matching", but would still return
commands like "vim /etc/slapd.conf" or ./myscript-slapd
about pgrep, like the usual grep, it needs a better expression than the
process name, otherwise it would return the same results as a grep

however, a perfect match may be done looking for the exact path
('[/]usr/local/bin/slapd '), but would still fail when, for ex. running
`objdump /usr/local/bin/slapd -x'
 also, if you want to count the number of outputed lines, using [p]grep and
wc makes two processes, while awk can do it all alone.

awk ftw!


On Wed, Jan 12, 2011 at 3:17 PM,  wrote:

> Hello
>
> I'm in trouble with a simple shell script that give
> erroneous value when running ...
>
> If I run commands interactively everything runs well
>
>  > ps ax | grep slapd | grep -v grep | wc -l
>   1
>
> If I run in the following shell script :
>
> #!/bin/sh
> SD=0
> SD=`ps -ax | grep slapd | grep -v grep | wc -l`
> echo $SD
>
> the result is 3 !!!
>
>
> Any info welcome !
>
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscr...@freebsd.org"
>
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscr...@freebsd.org"
>



-- 
Samuel Martín Moro
{EPITECH.} 2011
CamTrace S.A.S

"Nobody wants to say how this works.
 Maybe nobody knows ..."
  Xorg.conf(5)
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-13 Thread Julien Cigar

just use: pgrep "slapd"

On 01/12/2011 15:17, four.harris...@googlemail.com wrote:

Hello

I'm in trouble with a simple shell script that give
erroneous value when running ...

If I run commands interactively everything runs well

  >  ps ax | grep slapd | grep -v grep | wc -l
1

If I run in the following shell script :

#!/bin/sh
SD=0
SD=`ps -ax | grep slapd | grep -v grep | wc -l`
echo $SD

the result is 3 !!!


Any info welcome !

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"



--
No trees were killed in the creation of this message.
However, many electrons were terribly inconvenienced.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

problem with shell script

2011-01-13 Thread four . harrisons
Hello

I'm in trouble with a simple shell script that give
erroneous value when running ...

If I run commands interactively everything runs well

 > ps ax | grep slapd | grep -v grep | wc -l
   1

If I run in the following shell script :

#!/bin/sh
SD=0
SD=`ps -ax | grep slapd | grep -v grep | wc -l`
echo $SD

the result is 3 !!!


Any info welcome !

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-13 Thread Igor V. Ruzanov
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thu, 13 Jan 2011, per...@pluto.rain.com wrote:

|David Scheidt  wrote:
|
|> ps ax | grep [s]lapd | wc -l
|>
|> The [] creates a one-character class that doesn't match the regex.
|
|Doesn't [s]lapd need to be quoted?  [] are special to (at least some)
|shells.
Which FreeBSD version do you use? If it above 4.x you could try the 
following:

`pgrep slapd | wc -l'

 or maybe

`pgrep slapd | xargs ps | wc -l'

 or something like this, it depends on your criteria

+---+
! CANMOS ISP Network!
+---+
! Best regards  !
! Igor V. Ruzanov, network operational staff!
! e-Mail: ig...@canmos.ru   !
+---+
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: For info see http://quantumlab.net/pine_privacy_guard/

iD8DBQFNLserbt6QiUlK9twRAvApAKCoIAozDT98VzRkvE3bjPg9Fb2OZwCeLCVj
l86YACf0Sd+Gu2vfujQNE/I=
=pls0
-END PGP SIGNATURE-
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-13 Thread perryh
David Scheidt  wrote:

> ps ax | grep [s]lapd | wc -l
>
> The [] creates a one-character class that doesn't match the regex.

Doesn't [s]lapd need to be quoted?  [] are special to (at least some)
shells.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-12 Thread Jonathan McKeown
On Wednesday 12 January 2011 17:58:33 David Scheidt wrote:
>
> ps ax | grep [s]lapd | wc -l
>
> The [] creates a one-character class that doesn't match the regex.  Easier
> to type and grep should be a bit faster. 

And you can save another process by using

ps ax | grep -c '[s]lapd'

Although as others have pointed out, you can also use pgrep.

Jonathan
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-12 Thread Ryuichiro Hara

(2011/01/12 23:01), Frank Bonnet wrote:

Hello

I'm in trouble with a simple shell script that give
erroneous value when running ...

If I run commands interactively everything runs well

> ps ax | grep slapd | grep -v grep | wc -l
  1

If I run in the following shell script :

#!/bin/sh
SD=0
SD=`ps -ax | grep slapd | grep -v grep | wc -l`
echo $SD

the result is 3 !!!


Any info welcome !

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to 
"freebsd-questions-unsubscr...@freebsd.org"


hello.

i would rather use pgrep(1);
pgrep -afl slapd

for just counting purpose,
pgrep -a slapd | wc -l
is enough. it should work as expected in `` output.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-12 Thread Ryuichiro Hara

(2011/01/13 01:00), Warren Block wrote:

On Wed, 12 Jan 2011, Samuel Mart?n Moro wrote:

On Wed, Jan 12, 2011 at 3:50 PM, Chad Kellerman  
wrote:


On Wed, Jan 12, 2011 at 9:01 AM, Frank Bonnet  
wrote:



I'm in trouble with a simple shell script that give
erroneous value when running ...

If I run commands interactively everything runs well


ps ax | grep slapd | grep -v grep | wc -l

 1

If I run in the following shell script :

#!/bin/sh
SD=0
SD=`ps -ax | grep slapd | grep -v grep | wc -l`
echo $SD

the result is 3 !!!



ps ax | grep "[/]slapd " | wc -l
may not fix the problem
but still cleaner


ps axc | grep slapd | wc -l

is a little neater.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to 
"freebsd-questions-unsubscr...@freebsd.org"


hello.

i would rather use pgrep(1);
pgrep -afl slapd
for just counting purpose,
pgrep -a slapd | wc -l
is enough. i believe it should work all right as expected in `` output, 
as well.


___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-12 Thread Chip Camden
Quoth Frank Bonnet on Wednesday, 12 January 2011:
> Hello
> 
> I'm in trouble with a simple shell script that give
> erroneous value when running ...
> 
> If I run commands interactively everything runs well
> 
> > ps ax | grep slapd | grep -v grep | wc -l
>   1
> 
> If I run in the following shell script :
> 
> #!/bin/sh
> SD=0
> SD=`ps -ax | grep slapd | grep -v grep | wc -l`
> echo $SD
> 
> the result is 3 !!!
> 
> 
> Any info welcome !
> 
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Ever hear of pgrep(1)?

-- 
Sterling (Chip) Camden| sterl...@camdensoftware.com | 2048D/3A978E4F
http://camdensoftware.com | http://chipsquips.com   | http://chipstips.com


pgpzsxgMvlyzm.pgp
Description: PGP signature


Re: problem with shell script

2011-01-12 Thread Warren Block

On Wed, 12 Jan 2011, Samuel Mart?n Moro wrote:


On Wed, Jan 12, 2011 at 3:50 PM, Chad Kellerman  wrote:


On Wed, Jan 12, 2011 at 9:01 AM, Frank Bonnet  wrote:


I'm in trouble with a simple shell script that give
erroneous value when running ...

If I run commands interactively everything runs well


ps ax | grep slapd | grep -v grep | wc -l

 1

If I run in the following shell script :

#!/bin/sh
SD=0
SD=`ps -ax | grep slapd | grep -v grep | wc -l`
echo $SD

the result is 3 !!!



ps ax | grep "[/]slapd " | wc -l
may not fix the problem
but still cleaner


ps axc | grep slapd | wc -l

is a little neater.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-12 Thread David Scheidt

On Jan 12, 2011, at 10:43 AM, Samuel Martín Moro wrote:

> On W
>> 
 If I run in the following shell script :
 
 #!/bin/sh
 SD=0
 SD=`ps -ax | grep slapd | grep -v grep | wc -l`
 echo $SD
 
 the result is 3 !!!
 
>>> 
>> ps ax | grep "[/]slapd " | wc -l
>> 
> ps ax | awk '/[/]slapd /{n++} END{print n}'
> sorry...
> 
>> may not fix the problem
>> but still cleaner


ps ax | grep [s]lapd | wc -l

The [] creates a one-character class that doesn't match the regex.  Easier to 
type and grep should be a bit faster.  
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-12 Thread Samuel Martín Moro
On Wed, Jan 12, 2011 at 4:34 PM, Samuel Martín Moro wrote:

>
>
> On Wed, Jan 12, 2011 at 3:50 PM, Chad Kellerman wrote:
>
>> On Wed, Jan 12, 2011 at 9:01 AM, Frank Bonnet  wrote:
>>
>> > Hello
>> >
>> > I'm in trouble with a simple shell script that give
>> > erroneous value when running ...
>> >
>> > If I run commands interactively everything runs well
>> >
>> > > ps ax | grep slapd | grep -v grep | wc -l
>> >  1
>> >
>> > If I run in the following shell script :
>> >
>> > #!/bin/sh
>> > SD=0
>> > SD=`ps -ax | grep slapd | grep -v grep | wc -l`
>> > echo $SD
>> >
>> > the result is 3 !!!
>> >
>>
> ps ax | grep "[/]slapd " | wc -l
>
ps ax | awk '/[/]slapd /{n++} END{print n}'
sorry...

> may not fix the problem
> but still cleaner
>
>>  >
>> > Any info welcome !
>> >
>>
>> What's the name of your script?  Hope it's not slapd_check.sh that will
>> cause and extra count in the ps, cus it will count itself.
>>
>>
>> Chad
>>
>> >
>> > ___
>> > freebsd-questions@freebsd.org mailing list
>> > http://lists.freebsd.org/mailman/listinfo/freebsd-questions
>> > To unsubscribe, send any mail to "
>> > freebsd-questions-unsubscr...@freebsd.org"
>> >
>>
>>
>>
>> --
>> A grasshopper walks into a bar and the bartender says "Hey, we have a
>> drink
>> named after you." And the grasshopper says "Really, You have a drink named
>> Murray?"
>> ___
>> freebsd-questions@freebsd.org mailing list
>> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
>> To unsubscribe, send any mail to "
>> freebsd-questions-unsubscr...@freebsd.org"
>>
>
>
>
> --
> Samuel Martín Moro
> {EPITECH.} 2011
> CamTrace S.A.S
>
> "Nobody wants to say how this works.
>  Maybe nobody knows ..."
>   Xorg.conf(5)
>



-- 
Samuel Martín Moro
{EPITECH.} 2011
CamTrace S.A.S

"Nobody wants to say how this works.
 Maybe nobody knows ..."
  Xorg.conf(5)
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-12 Thread Samuel Martín Moro
On Wed, Jan 12, 2011 at 3:50 PM, Chad Kellerman  wrote:

> On Wed, Jan 12, 2011 at 9:01 AM, Frank Bonnet  wrote:
>
> > Hello
> >
> > I'm in trouble with a simple shell script that give
> > erroneous value when running ...
> >
> > If I run commands interactively everything runs well
> >
> > > ps ax | grep slapd | grep -v grep | wc -l
> >  1
> >
> > If I run in the following shell script :
> >
> > #!/bin/sh
> > SD=0
> > SD=`ps -ax | grep slapd | grep -v grep | wc -l`
> > echo $SD
> >
> > the result is 3 !!!
> >
>
ps ax | grep "[/]slapd " | wc -l
may not fix the problem
but still cleaner

>  >
> > Any info welcome !
> >
>
> What's the name of your script?  Hope it's not slapd_check.sh that will
> cause and extra count in the ps, cus it will count itself.
>
>
> Chad
>
> >
> > ___
> > freebsd-questions@freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> > To unsubscribe, send any mail to "
> > freebsd-questions-unsubscr...@freebsd.org"
> >
>
>
>
> --
> A grasshopper walks into a bar and the bartender says "Hey, we have a drink
> named after you." And the grasshopper says "Really, You have a drink named
> Murray?"
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscr...@freebsd.org"
>



-- 
Samuel Martín Moro
{EPITECH.} 2011
CamTrace S.A.S

"Nobody wants to say how this works.
 Maybe nobody knows ..."
  Xorg.conf(5)
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


Re: problem with shell script

2011-01-12 Thread Chad Kellerman
On Wed, Jan 12, 2011 at 9:01 AM, Frank Bonnet  wrote:

> Hello
>
> I'm in trouble with a simple shell script that give
> erroneous value when running ...
>
> If I run commands interactively everything runs well
>
> > ps ax | grep slapd | grep -v grep | wc -l
>  1
>
> If I run in the following shell script :
>
> #!/bin/sh
> SD=0
> SD=`ps -ax | grep slapd | grep -v grep | wc -l`
> echo $SD
>
> the result is 3 !!!
>
>
> Any info welcome !
>

What's the name of your script?  Hope it's not slapd_check.sh that will
cause and extra count in the ps, cus it will count itself.


Chad

>
> ___
> freebsd-questions@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "
> freebsd-questions-unsubscr...@freebsd.org"
>



-- 
A grasshopper walks into a bar and the bartender says "Hey, we have a drink
named after you." And the grasshopper says "Really, You have a drink named
Murray?"
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"


problem with shell script

2011-01-12 Thread Frank Bonnet

Hello

I'm in trouble with a simple shell script that give
erroneous value when running ...

If I run commands interactively everything runs well

> ps ax | grep slapd | grep -v grep | wc -l
  1

If I run in the following shell script :

#!/bin/sh
SD=0
SD=`ps -ax | grep slapd | grep -v grep | wc -l`
echo $SD

the result is 3 !!!


Any info welcome !

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"