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


Reply
  Search this Thread
Old 09-22-2009, 01:29 PM   #1
kishoreru
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Rep: Reputation: 0
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
 
Old 09-22-2009, 02:12 PM   #2
nuwen52
Member
 
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
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 02:15 PM. Reason: error in previous post
 
Old 09-22-2009, 02:28 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 09-22-2009, 03:41 PM   #4
lwasserm
Member
 
Registered: Mar 2008
Location: Baltimore Md
Distribution: ubuntu
Posts: 184

Rep: Reputation: 41
You might take a look at the "start-stop-daemon" program that is used in debian and possibly other distros.
 
Old 09-22-2009, 04:11 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by kishoreru View Post
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.
 
Old 09-22-2009, 07:25 PM   #6
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by kishoreru View Post
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)
 
Old 09-22-2009, 11:52 PM   #7
kishoreru
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Smile

Quote:
Originally Posted by lutusp View Post
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 :-)
 
Old 09-23-2009, 04:29 AM   #8
tikit
Member
 
Registered: Feb 2008
Posts: 85

Rep: Reputation: 16
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
Code:
kill -HUP 1
If the service stops in will be automatically started
 
  


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
bash: daemon: command not found linx win Fedora 3 02-16-2016 01:43 AM
bash script running as daemon Satriani Programming 12 03-29-2011 05:23 PM
Run my bash script as a daemon. jaimese Linux - Newbie 12 02-10-2011 03:28 PM
Enable daemon to run with service daemon start,etc baddah Programming 6 12-02-2007 05:51 PM
start a daemon script at startup haxxor23 Linux - Newbie 2 05-12-2007 07:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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