[Solved] Script doesn't work..help? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

[Solved] Script doesn't work..help?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-09-2013
zigizag zigizag is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 April 2013, 3:39 AM EDT
Posts: 28
Thanks: 18
Thanked 0 Times in 0 Posts
[Solved] Script doesn't work..help?

hi,

i am trying to run this script.the name of script is final.sh

after i run it:

Code:
#./final.sh &

i grep the command


Code:
# ps -a | grep bash

and i see more then one processes runing 3!!

Moderator's Comments:
Please use code tags


how can i solve this problem?

my target script must always run in background and watch there are always
5 process that are runing and if there is less it should get them up untill 5.



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
done
done
#let something else use the box done


Last edited by jim mcnamara; 01-09-2013 at 07:11 AM..
Sponsored Links
    #2  
Old 01-09-2013
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 20 December 2014, 1:13 AM EST
Location: In the leftmost byte of /dev/kmem
Posts: 4,371
Thanks: 47
Thanked 853 Times in 674 Posts
"bash" is a shell, not a script. If you search for "bash" in the process list you will find your scripts (because the use "bash" as their environment), but also interactive shells, login shells, other running scripts, etc.. Better use a more specific search term, which specifically finds your scripts instances and nothing else.

I hope this helps.

bakunin
The Following User Says Thank You to bakunin For This Useful Post:
zigizag (01-09-2013)
Sponsored Links
    #3  
Old 01-09-2013
zigizag zigizag is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 April 2013, 3:39 AM EDT
Posts: 28
Thanks: 18
Thanked 0 Times in 0 Posts
instead of running bash let say it is another script..

the problem is the same...
    #4  
Old 01-09-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 19 December 2014, 1:20 PM EST
Location: Switzerland - GE
Posts: 5,980
Thanks: 171
Thanked 440 Times in 412 Posts
Im very busy at the moment so have not much time to go in details...
The output of your ps might have helped us you know... (the complete!)
Look at the line 3 of your script...
The Following User Says Thank You to vbe For This Useful Post:
zigizag (01-09-2013)
Sponsored Links
    #5  
Old 01-09-2013
zigizag zigizag is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 April 2013, 3:39 AM EDT
Posts: 28
Thanks: 18
Thanked 0 Times in 0 Posts
instead of bash it is a script

the ps that i want to run is a script that runs application.

so instead of bash it is a script.

10x!
Sponsored Links
    #6  
Old 01-09-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 19 December 2014, 1:20 PM EST
Location: Switzerland - GE
Posts: 5,980
Thanks: 171
Thanked 440 Times in 412 Posts
I just put your script in order ( for me to read...):

Code:
#! /bin/bash
while true
do
   proc_num=$(ps a | grep yourscript | wc -l)
   echo "loop1: "proc_num=$proc_num
   sleep 2
   while (( $proc_num < 5 ))
      do
         echo "loop 2: "proc_num=$proc_num
         sleep 2
         yourscript &      #add a single process
         #sleep 1 # - this is for testing purpose... -#
         #let proc_num=$proc_num+1
      done
   echo " out of loop 1 "
   sleep 1
done
#let something else use the box done

Comment:
ps -a doesnt give the same as ps a
you were missing a space after second while...
My question is more on line launching yourscript: does it go in background like a daemon or not? if it doesnt I see your program being stuck at this point ( but I may be wrong since I dont know what program it is...)

Last edited by vbe; 01-09-2013 at 12:27 PM..
The Following User Says Thank You to vbe For This Useful Post:
zigizag (01-10-2013)
Sponsored Links
    #7  
Old 01-10-2013
zigizag zigizag is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 24 April 2013, 3:39 AM EDT
Posts: 28
Thanks: 18
Thanked 0 Times in 0 Posts
there is still a problem...

the .."$proc_num < 5 " doesnt work....it goes up and up and never stops of arising new scripts it runs more of my process.

alot of thanks!!!

---------- Post updated at 01:40 AM ---------- Previous update was at 01:39 AM ----------

there is still a problem...
the .."$proc_num < 5 " doesnt work....it goes up and up and never stops of arising new scripts it runs more of my process.

alot of thanks!!!

---------- Post updated at 01:45 AM ---------- Previous update was at 01:40 AM ----------

Hi,

i tested on runing wireshark application and it arises more and more...never stops..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
my script doesn't work :( keiserx Shell Programming and Scripting 3 12-08-2010 03:00 AM
Script doesn't work in loop but does if not bugeye Shell Programming and Scripting 6 08-03-2010 03:10 AM
Help with script.. it Just doesn't work atmosroll Shell Programming and Scripting 1 02-23-2010 07:30 PM
gcd.sh script doesn't work... kantze Shell Programming and Scripting 1 01-17-2008 09:46 PM
Script doesn't work, but commands inside work cheongww UNIX for Dummies Questions & Answers 2 11-14-2006 10:52 PM



All times are GMT -4. The time now is 07:29 AM.