Checking # of Process, ReStart a Process and Call another script

Checking # of Process, ReStart a Process and Call another script

Post by Jo » Fri, 22 Nov 2002 07:03:04



I have two questions and I am spending the whole day trying to figure
it out and decided to ask the expert.

1) My eval [eval $countRMI1098 -lt 3 ] does not work. Could you tell
me where I have to change. I search the deja.com but I don't see any
related subject.
2) I have cmrstart1098 file that I want to call in my korn shell
script. How could I do that? The cmrstart would have this command -
nohup rmiregistry 1098 > cmrlog1098.txt&

Thank for you help
Joe

#!/bin/ksh
countRMI1098=`ps -ef | grep -v grep | grep 1098 | wc`


messageJavaCoreDump="BOOGUS ! Just a test only.\n  Java Application
has a Core Dump.\nPlease restart all RMIs"
messageRMI1098="BOOGUS ! Just a test only.\nCMR 1098 RMIs were down
and have been restarted.\n"

if [ eval $countRMI1098 -lt 3 ]
   then
        ps -ef | grep -v grep | grep 1098 | awk '{print $2}' | xargs
kill
        cmrstart1098  
            echo messageRMI1098  | mail -s"RMI 1098 Restarted"  $notifyCMR
   else
        echo messageRMI1098  | mail -s"Everything is Okay"  $notifyCMR
fi

 
 
 

Checking # of Process, ReStart a Process and Call another script

Post by Dale Talco » Fri, 22 Nov 2002 17:14:35




...
>> 2) I have cmrstart1098 file that I want to call in my korn shell
>> script. How could I do that? The cmrstart would have this command -
>> nohup rmiregistry 1098 > cmrlog1098.txt&
...
>> #!/bin/ksh
>> countRMI1098=`ps -ef | grep -v grep | grep 1098 | wc`
>A few things:
>    typeset -i countRMI1098=$(ps -ef | grep "[1]098" | wc -l)
>is probably more appropriate.  'typeset -i' marks the variable
>as an integer variable.  'grep "[1]098"' makes 'grep -v grep'
>unnecessary.  I'm pretty sure you want 'wc -l', which counts the
>number of lines of input, instead of plain 'wc', which counts
>the number of bytes, words and lines.

Also, searching for just 1098 is risky.  It might appear as part of
a process id.  So, try something like

        typeset -i num_running_rmi=$(ps -u UUU -o args|
                awk '/[r]miregistry 1098/ { count++ } END {print count}')

Replace UUU with the user id you run the program under.  Replace the
"[r]miregistry 1098" part with whatever shows up if you do a

        ps -u UUU -o args

when things are running normally (putting [] around the first letter
of the text you want to match).

You should use the same technique when collecting the pids for the
processes you plan to kill.  Something like [untested]

        running_pids=$( ps -u UUU -o pid,args |
                awk '/[r]miregistry 1098/ { print $1 }' )
        if [[ -n "$running_pids" ]];then
                kill $running_pids
        fi
        ...

--
Dale Talcott, IT Research Computing Services, Purdue University


 
 
 

Checking # of Process, ReStart a Process and Call another script

Post by Jo » Sat, 23 Nov 2002 02:08:30


Hey Nick
Thanks for your help. Your suggestion is much better and simplier

Just to clear things up, the EVAL on my previous script did not work
but by using a TYPESET which you suggested, works better

Thanks !



> > I have two questions and I am spending the whole day trying to figure
> > it out and decided to ask the expert.

> > 1) My eval [eval $countRMI1098 -lt 3 ] does not work. Could you tell
> > me where I have to change. I search the deja.com but I don't see any
> > related subject.
> > 2) I have cmrstart1098 file that I want to call in my korn shell
> > script. How could I do that? The cmrstart would have this command -
> > nohup rmiregistry 1098 > cmrlog1098.txt&

> You don't say what the problem is.  Have you tried that syntax?  It
> looks OK to me.  Does the program start?  What happens?  Any errors?

> > #!/bin/ksh
> > countRMI1098=`ps -ef | grep -v grep | grep 1098 | wc`

> A few things:

>    typeset -i countRMI1098=$(ps -ef | grep "[1]098" | wc -l)

> is probably more appropriate.  'typeset -i' marks the variable
> as an integer variable.  'grep "[1]098"' makes 'grep -v grep'
> unnecessary.  I'm pretty sure you want 'wc -l', which counts the
> number of lines of input, instead of plain 'wc', which counts
> the number of bytes, words and lines.

> Also, try using less unreadable variable names -- names that
> don't contain numbers and that have a consistent case sceme.
> For example:

>    typeset -i num_running_rmi=$( . . . )

> or

>    typeset -i RUNNING_RMI_PROCS=$( . . . )

> something along those lines.


> > messageJavaCoreDump="BOOGUS ! Just a test only.\n  Java Application
> > has a Core Dump.\nPlease restart all RMIs"
> > messageRMI1098="BOOGUS ! Just a test only.\nCMR 1098 RMIs were down
> > and have been restarted.\n"

> Here's a simple example that might get you started.  Note that
> grep "[s]leep" is preferred to "grep -v grep | grep sleep" and
> wc -l is preferred to wc.

> #!/bin/ksh

> sleep 100 &
> sleep 100 &
> sleep 100 &

> typeset -i num_running_sleep=$(ps -ef | grep "[s]leep" | wc -l)

> print "There are $num_running_sleep sleeps in the process table"

> if [[ $num_running_sleep -lt 3 ]]
> then
>    print "Killing them"
>     kill $(ps -ef | grep "[s]leep" | awk '{ print $2 '})
> else
>    print "Not killing any"
> fi

> exit

> Regards,

> Nicholas

 
 
 

Checking # of Process, ReStart a Process and Call another script

Post by Nicholas Drone » Sat, 23 Nov 2002 02:29:29



> Hey Nick
> Thanks for your help. Your suggestion is much better and simplier
> Just to clear things up, the EVAL on my previous script did not work
> but by using a TYPESET which you suggested, works better

No problem, Joe.  Enjoy.

--
Do not reply to USENET posts, at least to mine, by email.

 
 
 

1. Cron Script to check & auto-restart the died process periodically

  We have some system processes running in background to ingest the realtime
  data from various ports. This processes are started at the boot time by
  rc.local.

  Now some time this processes dies due to some errors in the data feed

  So we need to periodically check that this processes are running and
  if not we need to restart the process. I think cron can do it but I don't
  know exactly how to check that process is running or not.


2. - FTP logins

3. start a process; check again; restart if not running

4. Help configuring hispeed serial card

5. How to check health of child process in a process group

6. UUCP over TAC

7. How do I check whether a process has died by using process ID in C?

8. Trouble making ip_masq* modules in 2.0.30

9. How to check the state of child process(s) in one process group

10. How do I check whether a process has died by using process ID?

11. system call starting next process before first process is finished.

12. How to check health of child process in a process group

13. How do I check whether a process has died by using process ID in C?