Download your favorite Linux distribution at LQ ISO.
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, 09: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 09:51 AM.
Old 11-13-2005, 03:35 AM   #2
Senior Member
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 47
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 03:53 AM.
Old 11-14-2005, 07:57 AM   #3
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 199Reputation: 199
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 04:33 PM
Apache server-status help javamdk Linux - Networking 4 03-27-2005 08:45 PM
Apache server-status help javamdk Ubuntu 1 03-27-2005 05:53 AM
when i startx the kde bring 2 bash program by it self Paxmaster Linux - General 1 11-11-2004 07:09 PM
apache monitoring problems- server-status?? lucastic Linux - Networking 0 08-10-2003 06:48 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:18 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