While loop true problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop true problem
# 1  
Old 01-09-2013
While loop true problem

hi,

i am new in bash scripting.
i am trying to write a Bash script to monitor how many process are running in my Redhat6 Linux machine.
example :
let say there must be always 5 process from the same kind that must run and if one off them fails down the script must wake up another process from the same kind.
doesn't mind if it is process or application

the problem is that if there are 5 process the scripts exits.
i dont want it to exit i want it to be like a watchdog......

Code:
#! /bin/bash

proc_num=$(ps -a | grep bash | wc -l)

while (( "$proc_num" < "5"))

do 

bash

done


Last edited by Scott; 01-09-2013 at 04:15 AM.. Reason: Code tags
# 2  
Old 01-09-2013
You're one loop short Smilie
Code:
#! /bin/bash
while true ; do
  proc_num=$(ps -a | grep bash | wc -l)
  while(( "$proc_num" < "5")) ; do
    bash #add a single process
  done
  sleep 10; #let something else use the box
done

This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 01-09-2013
ok 10x!!

but how can i get my prompt back?

after i run the script..

---------- Post updated at 05:09 AM ---------- Previous update was at 04:07 AM ----------

the scripts run runs in the background more then 1 time..3 times???

why is it? it doesnt make sense??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

While true loop stopped

Hello Team, In my shell script, it stopped without killing it. Could you please help why ? Below is the code : get_dpi44_currentFiles() { truncate --size 0 $dpi_44_fixed_currentFileList if ssh $dpi_srvr_44 -p 2222 "ls $dpi_44_sourceFilesDir/fixed | grep '\.tgz$'" >... (5 Replies)
Discussion started by: sadique.manzar
5 Replies

2. Shell Programming and Scripting

Problem with loop within loop

Hi, I work on Ab-initio ETL tool which is based on Unix. I made a small script which has two loop's one with in another. All the functionality is working for the first line of outer loop but when it comes to other lines of outer loop it is throwing error as command not found. Below is the... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

3. Shell Programming and Scripting

Explaination on if true

Hi Team, I need to know why ppl use If true loop instead of just writing down the sequence of code lines. 1: echo "Line1" if true; then echo "Line2" fi echo "Line3" 2: echo "Line1" echo "Line2" echo "Line3" Could you explain what does the if true loop make difference in 1st compare... (3 Replies)
Discussion started by: chandana hs
3 Replies

4. UNIX for Dummies Questions & Answers

Problem getting mailx to send true Bcc mail to multiple recipients

I am having trouble getting mailx to send multiple Bcc mails out without everyone in the list of recipients seeing everyone else's email addresses. I looked at the man pages of my system and seem to be following the syntax correctly, but the mails still go out as if I were just putting in a list of... (7 Replies)
Discussion started by: legrandtimonier
7 Replies

5. Shell Programming and Scripting

loop until true

Hi I need help with a script to loop unitl the statement is true done some thing like this until if then cp filename filename.anto fi done Regards, (3 Replies)
Discussion started by: antointoronto
3 Replies

6. UNIX for Dummies Questions & Answers

Funny but true....

Hallo everybody I am having a shell script called auto_run.sh in that only the first line works. the second line which has sed command is working only at the # prompt. not within the shell script. What could be the reason. *... sed 's/ //g' KTI >abc works in another shell script without the... (6 Replies)
Discussion started by: naushad
6 Replies

7. Shell Programming and Scripting

Bash: Exiting while true loop when terminal is not the focus window

I am running an Ubuntu Gutsy laptop with Advanced Compiz fusion options enabled. I am using xdotool to simulate keyboard input in order to rotate through multiple desktops. I am looking for a way to kill a while true loop when the Enter key (or Control+C if it is easier) is pushed when the... (2 Replies)
Discussion started by: acclaypool
2 Replies

8. Shell Programming and Scripting

how to exit a while true loop

Hi guys, I'm new to unix but loving it!! BUT this is driving me nuts as i can't work out the best way to do it. I have a while true loop that i use to monitor something. For my own reasons in ths script i have disabled the CTRL C using the trap command. But i want to put in a option to exit... (5 Replies)
Discussion started by: Noob e
5 Replies

9. UNIX for Dummies Questions & Answers

is it true or not

I have heard for a long time that in maybe 2039 Unix will no longer be useable due the length of the date value. Anyone know anything about this? (4 Replies)
Discussion started by: dhlopomo
4 Replies

10. UNIX for Dummies Questions & Answers

True Shutdown help!

ok, i know the syntax that goes along with the Shutdown command... but my box never wants to ... well... shutdown.. it only halts, kills all the process's, stalls the comp to a complete stop, but does actually kill the monitor and/or shut off the physical computer. it will reboot properly though,... (3 Replies)
Discussion started by: 01000101
3 Replies
Login or Register to Ask a Question