LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-27-2007, 03:35 PM   #1
TuxLives
Member
 
Registered: Sep 2003
Location: Tacoma, WA
Distribution: Mandriva all the way
Posts: 145

Rep: Reputation: 15
Shell script for Apache


I want a script that will

1. Check if apache is running
2. if so, echo "its running"
3. if not, start Apache
4. Check if apache is running (or has started or something) and echo "Apache started"

Any pointers?

PS

I can do this /usr/sbin/apachectl graceful just to make it happend, but I want to play with some shell scripting.

Last edited by TuxLives; 01-27-2007 at 03:39 PM.
 
Old 01-27-2007, 03:53 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well the service script in /etc/init.d/ will do this already. check it out.
 
Old 01-27-2007, 04:04 PM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Read the following manual pages:
pidof, pgrep, ps, grep, httpd, bash (for some things like shell expansion). You would better copy-and-paste apache launch command from init script (I do not think it is a good idea to master all switches of Apache web server without need), but all the rest is relatively easy. Find where pid file lies, read it, check that such PID exists, check it is owned by Apache.
 
Old 01-27-2007, 05:53 PM   #4
TuxLives
Member
 
Registered: Sep 2003
Location: Tacoma, WA
Distribution: Mandriva all the way
Posts: 145

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by raskin
Read the following manual pages:
pidof, pgrep, ps, grep, httpd, bash (for some things like shell expansion). You would better copy-and-paste apache launch command from init script (I do not think it is a good idea to master all switches of Apache web server without need), but all the rest is relatively easy. Find where pid file lies, read it, check that such PID exists, check it is owned by Apache.
I'm less concerned about the specifics because I am not doing any system administration. This is just for my dev machine at home.

Trying to learn a few things.
 
Old 01-27-2007, 06:34 PM   #5
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by TuxLives
I'm less concerned about the specifics because I am not doing any system administration. This is just for my dev machine at home.

Trying to learn a few things.
Quick and dirty way would be to use the ps command and grep for httpd, which is what the process is always listed as or run as.

From that point, if it's present, do nothing, if it's not, start it. I'll let you come up with the script so you actually learn something if you really want to develop your own bash script or Perl even.. whatever floats your boat..
 
Old 01-28-2007, 02:56 AM   #6
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
I was wrong.. httpd will start normally without any switches.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running shell script with PHP in Apache mr_scary Programming 2 10-20-2006 04:17 PM
Apache Stats Shell Script Pho Linux - General 1 12-18-2004 09:41 AM
Shell Script to Check apache installed or not. apt Programming 7 12-06-2004 11:07 PM
Apache passing arguments to a shell script disabled? mikeyt_333 Linux - Security 3 08-03-2004 06:09 PM
executing shell script on apache nooodles Linux - General 1 06-29-2004 01:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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