Re: simple shell script question
On 08/10/2017 10:07 AM, bruce wrote: > the test was to (1) replicate the results I get from the cmdline. > and to then (2) be able to pass a input/var to then generate the pgrep > count results > > the initial cmdline pgrep -- pgrep -f 'bash' | wc -l > -- on the test box, this returns a "50" count > > in testing using php/bash -- i get a "51" > > #!/bin/bash -f > # > # ptest.sh > # > > pgrep -f 'bash' | wc -l > > > > on the test centos box, there is no pgrep -c << option.. haven't > checked the fedora yet You do realize that when you execute the shell script ptest.sh you create one more process with "bash" in it? So [egreshko@meimei ~]$ pgrep -f 'bash' | wc -l 4 [egreshko@meimei ~]$ ./pt.sh 5 is totally correct. -- Fedora Users List - The place to go to speculate endlessly signature.asc Description: OpenPGP digital signature ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: simple shell script question
hey guys... appears to be user error... looks like i was on the wrong/older box.. on the updated centos/fed.. looks as i expected... at least for now! thanks.. On Wed, Aug 9, 2017 at 10:07 PM, brucewrote: > On Wed, Aug 9, 2017 at 9:52 PM, kevin martin wrote: >> is the end result meant to be able to pass some string ($1) to pgrep that >> get's counted? knowing what you're trying to accomplish would make it >> easier to help. >> >> --- >> > > - > > hey kevin. sorry. > > the test was to (1) replicate the results I get from the cmdline. > and to then (2) be able to pass a input/var to then generate the pgrep > count results > > the initial cmdline pgrep -- pgrep -f 'bash' | wc -l > -- on the test box, this returns a "50" count > > in testing using php/bash -- i get a "51" > > #!/bin/bash -f > # > # ptest.sh > # > > pgrep -f 'bash' | wc -l > > > > on the test centos box, there is no pgrep -c << option.. haven't > checked the fedora yet > > > however, if i replace "bash" with a procname that doesn't exist.. it > correctly returns "0".. > > So, I was/am trying to wrap my head around what's going on. > > thanks > > >> >> Regards, >> >> Kevin Martin >> >> On Wed, Aug 9, 2017 at 8:24 PM, bruce wrote: >>> >>> h update.. >>> >>> this works... >>> aa='bash' >>> echo $aa " pp" >>> xx= pgrep -f $aa | wc -l >>> echo $xx >>> >>> however, I can't seem to figure out how to enclose the aa var in >>> single quotes within the pgrep. >>> >>> thoughts/comments.. >>> >>> thanks >>> >>> >>> >>> >>> On Wed, Aug 9, 2017 at 8:47 PM, bruce wrote: >>> > trying to get the following to output >>> > pgrep -f 'bash' | wc -l >>> > >>> > the var $xx has the cmd... >>> > something's missing to allow the backtics to run the cmd.. >>> > if the cmd is hadcoded.run, it works.. >>> > >>> > can't see what the homer simpson "doh" moment is! >>> > >>> > thanks >>> > >>> > >>> > >>> > #!/bin/bash >>> > # >>> > # ptest.sh >>> > # >>> > # use predefined variables to access passed arguments >>> > # >>> > # $1 >>> > aa=$1 >>> > aa='bash' >>> > echo $aa " pp" >>> > xx="pgrep -f '"${aa}"' | wc -l" >>> > echo $xx <<< this dsplays the test pgrep >>> > echo `$xx` << err msg >>> > echo `${xx}` << err msg... >>> > >>> > ## trying to get -- pgrep -f 'bash' | wc -l << >>> > ## i'm getting a Usage: pgrep [] err msg.. >>> ___ >>> users mailing list -- users@lists.fedoraproject.org >>> To unsubscribe send an email to users-le...@lists.fedoraproject.org >> >> >> >> ___ >> users mailing list -- users@lists.fedoraproject.org >> To unsubscribe send an email to users-le...@lists.fedoraproject.org >> ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: simple shell script question
On Wed, Aug 9, 2017 at 9:52 PM, kevin martinwrote: > is the end result meant to be able to pass some string ($1) to pgrep that > get's counted? knowing what you're trying to accomplish would make it > easier to help. > > --- > - hey kevin. sorry. the test was to (1) replicate the results I get from the cmdline. and to then (2) be able to pass a input/var to then generate the pgrep count results the initial cmdline pgrep -- pgrep -f 'bash' | wc -l -- on the test box, this returns a "50" count in testing using php/bash -- i get a "51" #!/bin/bash -f # # ptest.sh # pgrep -f 'bash' | wc -l on the test centos box, there is no pgrep -c << option.. haven't checked the fedora yet however, if i replace "bash" with a procname that doesn't exist.. it correctly returns "0".. So, I was/am trying to wrap my head around what's going on. thanks > > Regards, > > Kevin Martin > > On Wed, Aug 9, 2017 at 8:24 PM, bruce wrote: >> >> h update.. >> >> this works... >> aa='bash' >> echo $aa " pp" >> xx= pgrep -f $aa | wc -l >> echo $xx >> >> however, I can't seem to figure out how to enclose the aa var in >> single quotes within the pgrep. >> >> thoughts/comments.. >> >> thanks >> >> >> >> >> On Wed, Aug 9, 2017 at 8:47 PM, bruce wrote: >> > trying to get the following to output >> > pgrep -f 'bash' | wc -l >> > >> > the var $xx has the cmd... >> > something's missing to allow the backtics to run the cmd.. >> > if the cmd is hadcoded.run, it works.. >> > >> > can't see what the homer simpson "doh" moment is! >> > >> > thanks >> > >> > >> > >> > #!/bin/bash >> > # >> > # ptest.sh >> > # >> > # use predefined variables to access passed arguments >> > # >> > # $1 >> > aa=$1 >> > aa='bash' >> > echo $aa " pp" >> > xx="pgrep -f '"${aa}"' | wc -l" >> > echo $xx <<< this dsplays the test pgrep >> > echo `$xx` << err msg >> > echo `${xx}` << err msg... >> > >> > ## trying to get -- pgrep -f 'bash' | wc -l << >> > ## i'm getting a Usage: pgrep [] err msg.. >> ___ >> users mailing list -- users@lists.fedoraproject.org >> To unsubscribe send an email to users-le...@lists.fedoraproject.org > > > > ___ > users mailing list -- users@lists.fedoraproject.org > To unsubscribe send an email to users-le...@lists.fedoraproject.org > ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: simple shell script question
On 08/09/2017 05:47 PM, bruce wrote: aa='bash' xx="pgrep -f '"${aa}"' | wc -l" echo $xx <<< this dsplays the test pgrep echo `$xx` << err msg echo `${xx}` << err msg... eval "$xx" or: echo $(eval "$xx") In the invocation you're trying to use, "|" is being passed as an argument to pgrep, rather than creating a pipe between commands/processes. ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: simple shell script question
is the end result meant to be able to pass some string ($1) to pgrep that get's counted? knowing what you're trying to accomplish would make it easier to help. --- Regards, Kevin Martin On Wed, Aug 9, 2017 at 8:24 PM, brucewrote: > h update.. > > this works... > aa='bash' > echo $aa " pp" > xx= pgrep -f $aa | wc -l > echo $xx > > however, I can't seem to figure out how to enclose the aa var in > single quotes within the pgrep. > > thoughts/comments.. > > thanks > > > > > On Wed, Aug 9, 2017 at 8:47 PM, bruce wrote: > > trying to get the following to output > > pgrep -f 'bash' | wc -l > > > > the var $xx has the cmd... > > something's missing to allow the backtics to run the cmd.. > > if the cmd is hadcoded.run, it works.. > > > > can't see what the homer simpson "doh" moment is! > > > > thanks > > > > > > > > #!/bin/bash > > # > > # ptest.sh > > # > > # use predefined variables to access passed arguments > > # > > # $1 > > aa=$1 > > aa='bash' > > echo $aa " pp" > > xx="pgrep -f '"${aa}"' | wc -l" > > echo $xx <<< this dsplays the test pgrep > > echo `$xx` << err msg > > echo `${xx}` << err msg... > > > > ## trying to get -- pgrep -f 'bash' | wc -l << > > ## i'm getting a Usage: pgrep [] err msg.. > ___ > users mailing list -- users@lists.fedoraproject.org > To unsubscribe send an email to users-le...@lists.fedoraproject.org > ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: simple shell script question
h update.. this works... aa='bash' echo $aa " pp" xx= pgrep -f $aa | wc -l echo $xx however, I can't seem to figure out how to enclose the aa var in single quotes within the pgrep. thoughts/comments.. thanks On Wed, Aug 9, 2017 at 8:47 PM, brucewrote: > trying to get the following to output > pgrep -f 'bash' | wc -l > > the var $xx has the cmd... > something's missing to allow the backtics to run the cmd.. > if the cmd is hadcoded.run, it works.. > > can't see what the homer simpson "doh" moment is! > > thanks > > > > #!/bin/bash > # > # ptest.sh > # > # use predefined variables to access passed arguments > # > # $1 > aa=$1 > aa='bash' > echo $aa " pp" > xx="pgrep -f '"${aa}"' | wc -l" > echo $xx <<< this dsplays the test pgrep > echo `$xx` << err msg > echo `${xx}` << err msg... > > ## trying to get -- pgrep -f 'bash' | wc -l << > ## i'm getting a Usage: pgrep [] err msg.. ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: simple shell script question
On 08/09/2017 05:47 PM, bruce wrote: > trying to get the following to output > pgrep -f 'bash' | wc -l > > the var $xx has the cmd... > something's missing to allow the backtics to run the cmd.. > if the cmd is hadcoded.run, it works.. > > can't see what the homer simpson "doh" moment is! It's kind of silly to pass that through "wc". Just use the "-c" option to pgrep: [root@prophead ~]# ps ax | grep bash | grep -v grep | wc -l 28 [root@prophead ~]# pgrep -f bash | wc -l 28 [root@prophead ~]# pgrep -c -f bash 28 I think PHP actually tacks on a blank line when executing the stuff in a backtick, so the "wc" value will always be 1 greater than the normal return. That's just a guess from doing a var_dump() on the output of the command: [root@prophead ~]# php -a Interactive shell php > var_dump(`pgrep -f bash | wc -l`); string(3) "29 " php > exit [root@prophead ~]# > #!/bin/bash > # > # ptest.sh > # > # use predefined variables to access passed arguments > # > # $1 > aa=$1 > aa='bash' > echo $aa " pp" > xx="pgrep -f '"${aa}"' | wc -l" > echo $xx <<< this dsplays the test pgrep > echo `$xx` << err msg > echo `${xx}` << err msg... > > ## trying to get -- pgrep -f 'bash' | wc -l << > ## i'm getting a Usage: pgrep [] err msg.. > ___ > users mailing list -- users@lists.fedoraproject.org > To unsubscribe send an email to users-le...@lists.fedoraproject.org > -- -- - Rick Stevens, Systems Engineer, AllDigitalri...@alldigital.com - - AIM/Skype: therps2ICQ: 226437340 Yahoo: origrps2 - -- - To understand recursion, you must first understand recursion.- -- ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: simple shell script question
unclear what you are trying to accomplish here. If, for example, you are trying to pgrep for all processes that have 'bash' in the process name: #!/bin/bash aa='bash' xx="pgrep -f ${aa} | wc -l" echo $xx <<< shows the command in $xx eval ${xx} <<< runs the command in $xx --- Regards, Kevin Martin On Wed, Aug 9, 2017 at 7:47 PM, brucewrote: > trying to get the following to output > pgrep -f 'bash' | wc -l > > the var $xx has the cmd... > something's missing to allow the backtics to run the cmd.. > if the cmd is hadcoded.run, it works.. > > can't see what the homer simpson "doh" moment is! > > thanks > > > > #!/bin/bash > # > # ptest.sh > # > # use predefined variables to access passed arguments > # > # $1 > aa=$1 > aa='bash' > echo $aa " pp" > xx="pgrep -f '"${aa}"' | wc -l" > echo $xx <<< this dsplays the test pgrep > echo `$xx` << err msg > echo `${xx}` << err msg... > > ## trying to get -- pgrep -f 'bash' | wc -l << > ## i'm getting a Usage: pgrep [] err msg.. > ___ > users mailing list -- users@lists.fedoraproject.org > To unsubscribe send an email to users-le...@lists.fedoraproject.org > ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
simple shell script question
trying to get the following to output pgrep -f 'bash' | wc -l the var $xx has the cmd... something's missing to allow the backtics to run the cmd.. if the cmd is hadcoded.run, it works.. can't see what the homer simpson "doh" moment is! thanks #!/bin/bash # # ptest.sh # # use predefined variables to access passed arguments # # $1 aa=$1 aa='bash' echo $aa " pp" xx="pgrep -f '"${aa}"' | wc -l" echo $xx <<< this dsplays the test pgrep echo `$xx` << err msg echo `${xx}` << err msg... ## trying to get -- pgrep -f 'bash' | wc -l << ## i'm getting a Usage: pgrep [] err msg.. ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org