LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 11-11-2005, 09:47 AM   #1
xbaez
Member
 
Registered: Mar 2004
Location: USA
Distribution: Ubuntu
Posts: 291

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


Ok I go to:
https://mysite.com:10000/status/index.cgi (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
apache_bring_up.sh

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 srv.site.com:80 *:* 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 srv.site.com:80 *:* 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
heema
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}'


here is a QUICKLY MADE AND UNTESTED script

Code:
#!/bin/bash

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
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
what about?

apachectl start stop restart?
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:27 PM.

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