bash script fails conditional test

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



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.

#!/bin/bash
pid=$(ps -ef | grep cassandra | grep -v grep | grep -i -v -e grep -e screen
-e s3fs|awk '{print $2}')

if [[ -e $pid ]]
then
  echo "Cassandra is running with pid: $pid"
else
  echo "Cassandra is DOWN!!!"
fi

But for some reason the script doesn't realize that the pid variable has
been set, and fails the condition. It then reports that Cassnadra is
DOWN!!!".

[root@web1:~] #sh -x ./bin/check-cass.sh
++ ps -ef
++ grep -v grep
++ grep -i -v -e grep -e screen -e s3fs
++ awk '{print $2}'
++ grep cassandra
+ pid=26979
+ [[ -e 26979 ]]
+ echo 'Cassandra is DOWN!!!'
Cassandra is DOWN!!!

Can anybody tell me where I'm going wrong here? Because from what I can
see, clearly the pid variable is being set so the script should be
reporting that cassandra is up!

I'd appreciate any advice you may have.


Thanks,
Tim

-- 
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