LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-13-2011, 04:25 PM   #1
dlugasx
Member
 
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-13-2011, 11:48 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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:
http://www.linuxcommand.org/index.php
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/index.html
http://www.gnu.org/software/bash/manual/bashref.html
http://wiki.bash-hackers.org/start
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls

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-13-2011 at 11:49 PM.
 
Old 06-14-2011, 03:35 AM   #3
dlugasx
Member
 
Registered: Dec 2008
Location: Germany/Poland
Distribution: CentOS / Debian / Solaris / RedHat
Posts: 266

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

thanks in advance
 
Old 06-14-2011, 07:27 AM   #4
mario.almeida
Member
 
Registered: May 2008
Location: India
Distribution: Ubuntu 10.04, CentOS, Manjaro
Posts: 179

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


Reply

Tags
bash, check, daemons, multiple, processes



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 06:28 PM
bash 'read' built-in with multiple processes reading same descriptor ta0kira Programming 41 09-13-2009 04:58 PM
Is 'nice' inherited to child processes? e.g. bash script/php script that calls MySQL SirTristan Linux - Newbie 1 12-04-2008 12:57 AM
help with script to check processes on multiple servers ncsuapex Programming 7 06-10-2008 11:02 AM
Script needed to check then restart application processes damoj Linux - Newbie 2 04-15-2008 02:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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