Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-11-2005, 10:47 AM   #1
Registered: Mar 2004
Location: USA
Distribution: Ubuntu
Posts: 284

Rep: Reputation: 30
Webmin Server Status + Bash program to bring Apache up

Ok I go to: (Webmin, Server Status)
Then I click on "Add Monitor of Type" -> "Apache webserver"
There is an option that sais "If monitor goes down, run command"

I want to creat a bash program

in which I will first run a netstat command to see if any other program is listening on port 80 or port 443, so that I can avoid the "(98) Address already in use" error

This is the program and the out put of it
# netstat --numeric-ports -lp | grep :80
tcp 0 0 *:* LISTEN 23508/httpd

Ok, so in this example PID 23508 is listening on port 80, the process name is httpd, but some time it happened that qmail was disturbing in those ports.

My main question is, how can I convert this command:
# netstat --numeric-ports -lp | grep :80
in another one that passes the output (in this case: tcp 0 0 *:* LISTEN 23508/httpd) and gives me only the PID?

I want to kill -9 xxxx that process, and then run start apache again

Thanks in advance

Last edited by xbaez; 11-11-2005 at 10:51 AM.
Old 11-13-2005, 04:35 AM   #2
Senior Member
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
you could make something like

netstat --numeric-ports -lp | grep :80 > test.txt

cat test.txt | awk '{print $7}' | awk -F / '{print $1}'



netstat --numeric-ports -lp | grep :80 > test.txt

PID=$(cat test.txt | awk '{print $7}' | awk -F / '{print $1}')

kill -9 $PID

apachectl restart

Last edited by heema; 11-13-2005 at 04:53 AM.
Old 11-14-2005, 08:57 AM   #3
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,371

Rep: Reputation: 192Reputation: 192
what about?

apachectl start stop restart?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
get exit status from a C-program in Bash Yoko Programming 1 07-12-2005 05:33 PM
Apache server-status help javamdk Linux - Networking 4 03-27-2005 09:45 PM
Apache server-status help javamdk Ubuntu 1 03-27-2005 06:53 AM
when i startx the kde bring 2 bash program by it self Paxmaster Linux - General 1 11-11-2004 08:09 PM
apache monitoring problems- server-status?? lucastic Linux - Networking 0 08-10-2003 07:48 PM

All times are GMT -5. The time now is 04:46 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration