Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 06-13-2011, 05:25 PM   #1
Registered: Dec 2008
Location: Germany/Poland
Distribution: CentOS / Debian / Solaris / RedHat
Posts: 266

Rep: Reputation: 19
Unhappy how to check multiple processes ? bash script...

Hi Gurus,

I have running license server on my server. Right now I would like to write small status script and check if software is running.

My software include 3 deamons:

1) daemonA
2) daemonB
3) daemonC

My script should check, if each of this deamon is running. If all deamons are running then script should print short output: "License server is running" if one of this daemons is not running, output should "License server is not running".

Is it possible to write small loop to check it ? Let say, loop will take new daemon name from deamons pool and will check if its running. Sometimes I need to check more than three daemons of one Program and I dont know how to write good script for this. Maybe somebody could help me with this loop that in the future I could also use; daemonD, daemonE, daemonF... etc.etc. if all daemons from pool is running then..."Software is running"

Would be great if somebody could help me ?
Old 06-14-2011, 12:48 AM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
It should be quite simple to set something like this up. But it would be best if you did most of the work yourself, so you'll learn more.

Start by figuring out how to generate the list of daemons you want using shell commands (do you want it to read from a simple text file, or grab the output from some other program?). Then figure out how to test whether a single daemon is running or not (hint: try grepping ps, or use pgrep). Then, determine how to print a message depending on its status (hint: use an if or case statement).

Once you have the individual steps mapped out, then you can wrap it up in a simple loop to test them all in turn.

Here are a few useful bash scripting references:

We'll be here to help you out if you encounter any problem points.
Good luck!

PS: Could you please remove or break up the hash lines in you signature? It's causing my browser to side-scroll something terrible. Thanks.

Last edited by David the H.; 06-14-2011 at 12:49 AM.
Old 06-14-2011, 04:35 AM   #3
Registered: Dec 2008
Location: Germany/Poland
Distribution: CentOS / Debian / Solaris / RedHat
Posts: 266

Original Poster
Rep: Reputation: 19
sitepoint=`ps aux | grep -v grep | egrep -c 'daemonA|daemonB|daemonC'`
if [ $sitepoint -lt "3" ]; then
 echo "Software is RUNNING"
 echio "Software is NOT RUNNING"
I have found this on forum and works like a charm but I dont understand this line...
if [ $sitepoint -lt "3" ]; then
what is mean "-lt" from which command is this parameter ?

thanks in advance
Old 06-14-2011, 08:27 AM   #4
Registered: May 2008
Location: India
Distribution: Ubuntu 10.04, CentOS
Posts: 179

Rep: Reputation: 27
-lt = less then
1 members found this post helpful.


bash, check, daemons, multiple, processes

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Bash backup script with scp, multiple processes mky Programming 8 09-29-2010 07:28 PM
bash 'read' built-in with multiple processes reading same descriptor ta0kira Programming 41 09-13-2009 05:58 PM
Is 'nice' inherited to child processes? e.g. bash script/php script that calls MySQL SirTristan Linux - Newbie 1 12-04-2008 01:57 AM
help with script to check processes on multiple servers ncsuapex Programming 7 06-10-2008 12:02 PM
Script needed to check then restart application processes damoj Linux - Newbie 2 04-15-2008 03:04 AM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:53 PM.

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