Can I do this? (start but maybe!)

Can I do this? (start but maybe!)

Post by Tom Edelbro » Mon, 25 Dec 2000 00:23:55



I want to use a script to start a process, but only if it is not already
running, because otherwise each new one stays in the system (along with any
old processes) until my machine is boggled. Therefore I want the script to
start the process if it is not running, but not start it if it is already
running.

I can see the process in "ps -A". So it there a way in a script of saying
something like this:

if  (ps -A  |  grep -i <myprocessname>) = (yup I found it) then
  do nothing
else
  start the <myprocessnamething>
  echo "I am a very happy Linux user who is still learning the basics of
BASH"
end if

Obviously I am familiar with VB and not so much with BASH script, but you
get my idea. Any ideas appreciated!

Thanks,
Tom

 
 
 

Can I do this? (start but maybe!)

Post by Tom Edelbro » Mon, 25 Dec 2000 14:40:59


I think I have it - I made a bash script using case, cut, and grep. If the
process is in "ps -A" then I do nothing, but if it isn't in the process list
I run it.

Tom


Quote:> I want to use a script to start a process, but only if it is not already
> running, because otherwise each new one stays in the system (along with
any
> old processes) until my machine is boggled. Therefore I want the script to
> start the process if it is not running, but not start it if it is already
> running.

> I can see the process in "ps -A". So it there a way in a script of saying
> something like this:

> if  (ps -A  |  grep -i <myprocessname>) = (yup I found it) then
>   do nothing
> else
>   start the <myprocessnamething>
>   echo "I am a very happy Linux user who is still learning the basics of
> BASH"
> end if

> Obviously I am familiar with VB and not so much with BASH script, but you
> get my idea. Any ideas appreciated!

> Thanks,
> Tom


 
 
 

Can I do this? (start but maybe!)

Post by phi » Tue, 26 Dec 2000 06:50:58



the following lines of wisdom:

Quote:>I want to use a script to start a process, but only if it is not already
>running, because otherwise each new one stays in the system (along with any
>old processes) until my machine is boggled. Therefore I want the script to
>start the process if it is not running, but not start it if it is already
>running.

>I can see the process in "ps -A". So it there a way in a script of saying
>something like this:

>if  (ps -A  |  grep -i <myprocessname>) = (yup I found it) then
>  do nothing
>else
>  start the <myprocessnamething>
>  echo "I am a very happy Linux user who is still learning the basics of
>BASH"
>end if

>Obviously I am familiar with VB and not so much with BASH script, but you
>get my idea. Any ideas appreciated!


(20:43)
USER   PID %CPU %MEM   VSZ  RSS  TT  STAT STARTED      TIME COMMAND
phil  3056  0.0  0.2  1300 1072  q1  Ss    8:27PM   0:00.14 -zsh (zsh)
phil  3135  0.0  0.2  1300 1072  q2  Is    8:27PM   0:00.10 -zsh (zsh)
phil 12852  0.0  1.0  5416 5128  q2  S+    8:36PM   0:03.93 slrn -h
news.dcu.ie
phil 20012  0.0  0.0   388  216  q1  R+    8:43PM   0:00.00 ps ux

My processes are starting as such, so count the number of fields over
separated by a space..


(20:43)
COMMAND
sh
-zsh
slrn
-zsh
vim
ps
-zsh

That gives me the base command... so now..

(20:45)
12852

returns the PID we want to kill..

Therefore
kill -9 `ps ux | awk '$11 == "slrn" {print $2}'`

Substitute in the fields on your system, I'm using a FreeBSD box here with
psutils and probably a different version of ps and hence a different
formatting scheme, the principle is the same though.
Phil.

 
 
 

1. maybe samba maybe w95

Umm,
is there anyway to tell all the machines using ms-networking
that old workgroups do not exist anymore and to quit displaying them
when they are not there.?

i think it might have something to do with the master browser thing

any ideas?

shohn

2. more than 1 IP address

3. Slow starting X: maybe a bug?

4. using 'select'

5. NFS write got EIO on kernel starting from 2.4.19-pre4 (or -pre3 maybe)

6. 2nd card of 3C509

7. raid1 problems in 2.5.26 (maybe started at .1?)

8. Automatic Starting of Scripts?

9. It's not bad canned meat...

10. Canned Proxy URLs to Filter

11. CGI: apache canned response

12. For those of you tired of canned distributions...