Application server is running or not


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Application server is running or not
# 1  
Application server is running or not

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.

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

Code:
{"'name'":"'nginx'","'pid'":"'/etc/nginx/nginx.conf /tmp/nginx.conf'", "'pid'":"'18508'"}

But desired output :

Code:
{"'name'":"'nginx'","'pid'":"'/etc/nginx/nginx.conf '", "'pid'":"'18508'"},
{"'name'":"'nginx'","'pid'":"' /tmp/nginx.conf '", "'pid'":"'18508'"}


Last edited by Scrutinizer; 11-04-2019 at 03:47 PM.. Reason: code tags + spelling corrections
# 2  
Think you have a typo in the output and expected output. These should contain "location" not "pid" for paths right?

Try replacing this:
Code:
echo -e "{\"'name'\":\"'"nginx"'\",\"'location'\":\"'"$var"'\", \"'pid'\":\"'"$process_id"'\"}"

with this
Code:
for loc in $var
do
    echo -e "{\"'name'\":\"'"nginx"'\",\"'location'\":\"'"$loc"'\", \"'pid'\":\"'"$process_id"'\"}"
done

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #729
Difficulty: Medium
BASIC stands for Basic All-purpose Symbolic Instruction Code.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to interrupt running application?

Hello i have problem passing ctrl+C into shell script this script will run application and return value but never ends and stay running. i tried trap and not working at all the command should look like this : sarm pcsp -s CHG_M_P1 i want something to stop this command after... (9 Replies)
Discussion started by: mogabr
9 Replies

2. UNIX for Dummies Questions & Answers

How to start application and keep script running

What I'm looking for is best explained with a little example. #!/bin/bash gedit echo "I need this message to appear while gedit is still running, but it appears only then when I close gedit." Of course most of the times you want the script to wait, but in this case I want to start a new... (5 Replies)
Discussion started by: MrZehl
5 Replies

3. UNIX and Linux Applications

Exceptions while running application on headless linux

I want to install executable file(Demo.bin) on vMA4.0 virtual machine using ssh. Same can be installed on all other Linux/Unix box. but when I am trying to run it on vMA,I am getting the following error-- Could you please advise me how to approch this problem and how to resolve it? (4 Replies)
Discussion started by: smartgupta
4 Replies

4. Shell Programming and Scripting

Know when a particular application is running

Is it possible in unix to write a script that could determine when a particular application is running or not ? (3 Replies)
Discussion started by: zapper222
3 Replies

5. Shell Programming and Scripting

To access UNIX server from Tk application running on Windows

Hi, I am new to this forum and this is my first post. I want to know that if I make an application in Tk (version of Tcl to create GUI) in windows and want to run to UNIX server, is it possible ? In other words, can I access a UNIX server through a Tk application running on windows ? ... (1 Reply)
Discussion started by: ratneshnagori
1 Replies

6. Solaris

How to find an application running on multithread?

Dear Friends, We have one T5240 server with 128vcpus in our lab.Performance of the server is very poor. Application uses only 2% of processor..I heard that single thread application performs slowly in coolthread.How can we find whether the application running on multithread or single thread? If... (7 Replies)
Discussion started by: nicktrix
7 Replies

7. Shell Programming and Scripting

command to know the application running of the port

Hi, is there any command to findout that which application is using the particular port. or whether any port is occupied with the specfic process id ? (4 Replies)
Discussion started by: mail2sant
4 Replies

8. UNIX for Dummies Questions & Answers

Running server side application on client demand

Ive written a java based "webscraper to rss feed" which resides on my college web space when I execute the app from putty it creates the feed and sets the permissions perfectly.I then wrote a php script to execute the app on demand from the browser using ... system("java -cp... (1 Reply)
Discussion started by: gleesonger
1 Replies

9. UNIX for Dummies Questions & Answers

Script to Test Application Server is running

Hi, I'm a complete novice at Unix and need to create a script that does the following... checks to see if an application server is running. If the app is running then print 'Available' Else print 'Unavaliable' exit from scriopt I have no idea where to start. I'd be very grateful... (0 Replies)
Discussion started by: duglover
0 Replies

Featured Tech Videos