Shell script to parse apache httpd line


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Shell script to parse apache httpd line
# 1  
Old 02-24-2011
Shell script to parse apache httpd line

Hello,

I have serveral SUN Web servers that need to write a KSH to figure out where Apache is installed and, tar up the directory (for backup purposes) once a month. The trick is that Apache is not installed in same location. So when I do "ps -ef| grep httpd" it shows on some boxes from /usr/local and, on some shows /app. the ones from /app I have the following
ps -fe|grep httpd | awk '{print $8}' to get where apache is running from like so:
www 26228 26215 0 16:01:02 ? 0:00 /app/apache-idmadmin/bin/httpd -k

but, on some other boxes I have to modify my ps to ps -ef| grep httpd | awk '{print $9}' because of the following
www 10303 10295 0 Feb 10 ? 1:28 /usr/local/apache2/bin/httpd -k start
. I would like to write a script that works no matter where httpd is running from.


Appreciate any help
# 2  
Old 02-24-2011
Try this :

Code:
ps -ef | grep [h]ttpd | sed 's:^[^/]*::;s: .*::'

or
Code:
ps -ef | sed '/[h]ttpd/!d;s:^[^/]*::;s: .*::'


Note :
[h]ttpdi instead of just httpd is a tip to avoid the "grep -v grep"
You also can speed up the process by displaying the first occurrence you will find and then quit the sed loop (by adding a ;q at the end of the sed command), so that if you have multiple httpd deamon, it will only display the first occurrence found.

Code:
ps -ef | grep [h]ttpd | sed 's:^[^/]*::;s: .*::;q'

If you have more than 1 apache so several httpd running at different location you might use the command without the ;q and add a | uniq

Even better, you can even save the grep pipe with :

Code:
ps -ef | sed '/[h]ttpd/!d;s:^[^/]*::;s: .*::;q'


Last edited by ctsgnb; 02-24-2011 at 02:26 PM..
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 02-24-2011
Thanks a lot ctsgnb. This is awesome. exactly what I needed. I had sort and, uniq already for my first akw '{print $8}' . your help greatly appreciated
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Locate which httpd.conf is used by Apache

What is the command to see what httpd.conf file is apache using. Apache is started. (1 Reply)
Discussion started by: galford
1 Replies

2. AIX

Apache httpd appear too many times on processes

Dear all experts, I have a environment with 2 web, 2 apps and 2 db servers. Recently after I have patch the AIX O/S from 5300-11-02 to 5300-12-02, we found that the number of httpd processes increase largely. From originally 4 fix httpd processes become more than 600 processes. And it already... (1 Reply)
Discussion started by: kwliew999
1 Replies

3. Red Hat

apache 2.2 httpd.conf

Hi, I was wondering if someone could help me out here. I am super-paranoid, so am trying to limit what PHP files can be executed on this server. I have a small list of files that I want to allow. The rest, deny: <Files ~ "\.(php|php3)$"> order allow,deny deny from all </Files> I... (0 Replies)
Discussion started by: Lobster
0 Replies

4. Red Hat

apache 2.2 httpd.conf

Hi, I was wondering if someone could help me out here. I am super-paranoid, so am trying to limit what PHP files can be executed on this server. I have a small list of files that I want to allow. The rest, deny. So I have base rule that denies all php files server-wide: order allow,deny ... (0 Replies)
Discussion started by: Lobster
0 Replies

5. Web Development

servername in apache httpd.conf

I'd like to know if servername in apache httpd.conf is the machine name or domain name. If it is domain name like example.com, should it be registered before in use? (1 Reply)
Discussion started by: yzhang738
1 Replies

6. Shell Programming and Scripting

Parse file from 2nd line in shell script

Hi, I need to parse input file from 2nd line. Input file contents are, ABC123;20100913115432;2000000;NO; 04;AAA;09;DDD;601020304;AAAA;1;OPTA1;OPTA2;;; 04;BBB;09;BBB;601020304;BBBB;0;OPTB1;OPTB2;OPTB3;OPTB4;OPTB5; 04;CCC;09;DDD;601020304;CCCC;1;;;;; For each line, 1] I need to check... (17 Replies)
Discussion started by: Poonamol
17 Replies

7. UNIX for Advanced & Expert Users

Building Apache httpd 2.2.15

Hi, What options should I use with ./configure to include mod_dav into the build? I use --enable-dav and I didn't see mod_dav.so anywhere in the build directory. I need to load mod_dav.so as a module during httpd startup. Thanks. (1 Reply)
Discussion started by: Parker_
1 Replies

8. Shell Programming and Scripting

Shell script to parse a line and insert a word

Hi All, I have a file like this, data1,data2,,,data5,data6. i want to write a shell script to replace data3 with "/example/string". which means my data file should look like this . data1,data2,example/string],,data5,data6. Could you guys help me to get a sed command or any other command... (8 Replies)
Discussion started by: girish.raos
8 Replies

9. Ubuntu

Apache 2 httpd.conf empty

Hi everybody, I have installed Apache 2 + Tomcat 5.5. on Ubuntu 7.04 and the default httpd.conf is empty (0 lines), however there is a file called apache2.conf that looks like a default httpd.conf. I didn't use Apache in ages, since 1.3.x release, but I remember that the httpd.conf by default... (2 Replies)
Discussion started by: sspirito
2 Replies
Login or Register to Ask a Question