Hi All,
i am trying to find whether nginx is installed or not as well process is running or not on my centos server.
For that i am searching for the nginx configuration file nginx.conf based on that i am printing the ouput.
Below script i am using.
var=$(find / -name "nginx.conf" ! -size 0 |egrep -v "roles")
#echo "$var"
if [ -z "$var" ]
then
echo "nginx : nginx is not installed"
elif
pgrep -x "nginx" > /dev/null
then
process_id=$(netstat -ltnp | grep -w nginx |grep -v tcp6 |tr -s " " |awk -F " " '{print $7}'|awk -F "/" '{print $1}')
port_number=$(netstat -ltnp | grep -w nginx |grep -v tcp6 |tr -s " " |awk -F " " '{print $4}' |awk -F ":" '{print $2}')
echo -e "{\"'name'\":\"'"nginx"'\",\"'location'\":\"'"$var"'\", \"'pid'\":\"'"$process_id"'\"}"
else
echo "Status : Not running "
echo "pid : None"
echo "port_number : None"
fi
am getting output as below :
{"'name'":"'nginx'","'pid'":"'/etc/nginx/nginx.conf /tmp/nginx.conf'", "'pid'":"'18508'"}
But desired output :
{"'name'":"'nginx'","'pid'":"'/etc/nginx/nginx.conf '", "'pid'":"'18508'"},
{"'name'":"'nginx'","'pid'":"' /tmp/nginx.conf '", "'pid'":"'18508'"}