Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
09-22-2009, 02:29 PM
|
#1
|
LQ Newbie
Registered: Sep 2006
Posts: 2
Rep:
|
Bash script to verify the daemon is working if not, start the daemon
Hi,
I need to write a bash script to verify some xyz daemon is running are not, if not start that xyz daemon
Any help would be appreciated...
Thanks is Advance
|
|
|
09-22-2009, 03:12 PM
|
#2
|
Member
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208
Rep:
|
A lot of daemons store their process ID in a file in /var/run (ex. sshd.pid for the sshd daemon). You might try looking there. Then if you find it, you can do an 'if [ -x "/proc/<PID>" ]' to see if the process directory exists. Otherwise, just a grep through a "ps -ax" for the daemon name might be enough.
Last edited by nuwen52; 09-22-2009 at 03:15 PM.
Reason: error in previous post
|
|
|
09-22-2009, 03:28 PM
|
#3
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
If the xyz daemon init script is fully featured then the commands you need are
Code:
/etc/init.d/xyz status
and
Code:
/etc/init.d/xyz start
or maybe restart would be safer -- cleaning up after a crashed daemon. You can find out more by inspecting the /etc/init.d/xyz script.
|
|
|
09-22-2009, 04:41 PM
|
#4
|
Member
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184
Rep:
|
You might take a look at the "start-stop-daemon" program that is used in debian and possibly other distros.
|
|
|
09-22-2009, 05:11 PM
|
#5
|
Moderator
Registered: May 2001
Posts: 29,415
|
Quote:
Originally Posted by kishoreru
I need to write a bash script to verify some xyz daemon is running are not, if not start that xyz daemon
|
If "need to write" is not due to some class assignment then unless you're into reinventing the wheel I'd look at something like Monit instead. It'll be faster than interpreted code, more configurable than you can script in one month and it's used, supported, maintained OSS.
|
|
|
09-22-2009, 08:25 PM
|
#6
|
Member
Registered: Sep 2009
Distribution: Fedora
Posts: 835
Rep:
|
Quote:
Originally Posted by kishoreru
Hi,
I need to write a bash script to verify some xyz daemon is running are not, if not start that xyz daemon
Any help would be appreciated...
Thanks is Advance
|
This is just a hint, not a complete solution (because your question sounds like homework).
Code:
# service httpd status | grep -iqP "\brunning\b" && (do something here)
|
|
|
09-23-2009, 12:52 AM
|
#7
|
LQ Newbie
Registered: Sep 2006
Posts: 2
Original Poster
Rep:
|
Quote:
Originally Posted by lutusp
This is just a hint, not a complete solution (because your question sounds like homework).
Code:
# service httpd status | grep -iqP "\brunning\b" && (do something here)
|
Thanks lutusp & All
I am new to Linux and Bash may be my question sounds like a homework :-)
|
|
|
09-23-2009, 05:29 AM
|
#8
|
Member
Registered: Feb 2008
Posts: 85
Rep:
|
You can use init to control the service. Put this line to /etc/inittab
Code:
ap:2345:respawn:/usr/sbin/apache2
and reload the init process
If the service stops in will be automatically started
|
|
|
All times are GMT -5. The time now is 11:47 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|