Httpd Automatic Start If DOWN, Urgent Assistance Required , please help

Posted on 2003-03-08
Medium Priority
Last Modified: 2013-12-15
Dear Sir,

I have enter the following command in my crond as you can see the first line is checking if the httpd is running if its down then then it will restart the HTTPD service . The problem which I am getting is whenever I enter those following line in my cron it never work. Is there any other command or any other way you could help me please.

* * * * * /bin/ps ax | /bin/grep '[/]sbin/httpd'> /dev/null 2> /dev/null
*/1 * * * * /bin/ps ax | /bin/grep '[/]sbin/httpd' || service httpd restart> /dev/null 2> /dev/null


Question by:sohaib69
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

majorwoo earned 2000 total points
ID: 8095638
there are a number of things here, ps -ax can possibly get you:

[root@daboss root]# ps -ax | grep httpd
25290 ?        S      0:00 /usr/sbin/httpd
25295 ?        S      0:00 /usr/sbin/httpd
25296 ?        S      0:00 /usr/sbin/httpd
25297 ?        S      0:00 /usr/sbin/httpd
25298 ?        S      0:00 /usr/sbin/httpd
25299 ?        S      0:00 /usr/sbin/httpd
25300 ?        S      0:00 /usr/sbin/httpd
25301 ?        S      0:00 /usr/sbin/httpd
25302 ?        S      0:00 /usr/sbin/httpd
25318 pts/0    S      0:00 grep httpd

so even if httpd is not running you can get the grep httpd line
you want a script to run that does that for you:


#check of httpd is running
ALIVE=`/bin/ps -e | grep httpd`

#if it is not running restart it
if [ ! "$ALIVE" ]; then
  service httpd restart >/dev/null 2>/dev/null
  #or if you prefer
  #/etc/init.d/httpd restart >/dev/null 2>/dev/null

exit 0

then call that script from your crontab

Expert Comment

ID: 8095847

If you are running redhat.
Try this at command line:
/etc/init.d/httpd status

If this works you'll get som pids and a word running.
I would rather do my grep check on this than on the process itself.

You might also checkout supervise progr to do this for you.

/Hans - Erik Skyttberg

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question