Re: bash script fails conditional test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



>
> "-e" means "if file exists".  You should use "-n"


That did it!!

[root@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@xxxxxxxxxxx> 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@xxxxxxxxxx
> http://lists.centos.org/mailman/listinfo/centos
>



-- 
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux