> > "-e" means "if file exists". You should use "-n"That did it!! [root at web1:~] #./bin/check-cass.sh Cassandra is running with pid: 26979 This is what the script looks like now: #!/bin/bash pid=$(ps -ef | grep cassandra | grep -v grep | grep -i -v -e grep -e screen -e s3fs|awk '{print $2}') if [[ -n $pid ]] then echo "Cassandra is running with pid: $pid" else echo "Cassandra is DOWN!!!" fi Insert an extra line after #!/bin/bash> set -xv > which will show helpful debug messages.Good tip! But I ran the script with sh +x . I guess that running it with sh +xv would do the same thing. But that is a useful tip to include the debug lines right in the script. I'll have to remember that for next time! Thanks! :) Tim On Sun, Apr 19, 2015 at 1:55 PM, Always Learning <centos at u64.u22.net> wrote:> > On Sun, 2015-04-19 at 13:15 -0400, Tim Dunphy wrote: > > Hey all, > > > > I wrote a very basic script to determine if cassandra db is running. I'm > > setting a variable called 'pid' to the output of a ps | grep like to grab > > the pid of the cassandra process. > > Insert an extra line after #!/bin/bash > > set -xv > > which will show helpful debug messages. > > > -- > Regards, > > Paul. > England, EU. Je suis Charlie. > > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >-- GPG me!! gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
On Sun, Apr 19, 2015 at 09:40:29PM -0400, Tim Dunphy wrote:> Good tip! But I ran the script with sh +x . I guess that running it with shYou should use "bash -x" ("bash" and not "sh" because sh may not be bash everywhere; eg Ubuntu; "-x" and not "+x" because "-x" means "turn on debug" but "+x" means "turn _off_ debug") -- rgds Stephen
Once upon a time, Tim Dunphy <bluethundr at gmail.com> said:> pid=$(ps -ef | grep cassandra | grep -v grep | grep -i -v -e grep -e screen > -e s3fs|awk '{print $2}')You can probably replace that with a much cleaner pid=$(pidof cassandra). -- Chris Adams <linux at cmadams.net>
Once upon a time, Stephen Harris <lists at spuddy.org> said:> On Sun, Apr 19, 2015 at 09:40:29PM -0400, Tim Dunphy wrote: > > Good tip! But I ran the script with sh +x . I guess that running it with sh > > You should use "bash -x" ("bash" and not "sh" because sh may not be bash > everywhere; eg Ubuntu; "-x" and not "+x" because "-x" means "turn on debug" > but "+x" means "turn _off_ debug")Unless you have specific bashisms (which I don't think the original did, and you should mostly avoid in scripts), sh -x will be fine. -- Chris Adams <linux at cmadams.net>
> > You can probably replace that with a much cleaner pid=$(pidof cassandra).Good to know! I hadn't heard of pidof before. However this is what I get when I run it: [root at web1:~] #pidof cassandra [root at web1:~] # Returns nothing. However: [root at web1:~] #pidof java 27210 11418 10852 Gives me a few pids. Only one of which belongs to cassandra, as I have a few java processes running. I still find that my little script isolates exactly the pid of cassandra that I would need to shutdown. [root at web1:~] #check-cass.sh Cassandra is running with pid: 27210 I really need to turn this into an init script. Which I probably will. But this is just for a hobby project ,and I'm a little too lazy to do it this weekend. Maybe next weekend. Thanks, Tim On Sun, Apr 19, 2015 at 9:58 PM, Chris Adams <linux at cmadams.net> wrote:> Once upon a time, Tim Dunphy <bluethundr at gmail.com> said: > > pid=$(ps -ef | grep cassandra | grep -v grep | grep -i -v -e grep -e > screen > > -e s3fs|awk '{print $2}') > > You can probably replace that with a much cleaner pid=$(pidof cassandra). > > -- > Chris Adams <linux at cmadams.net> > _______________________________________________ > CentOS mailing list > CentOS at centos.org > http://lists.centos.org/mailman/listinfo/centos >-- GPG me!! gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B