Script to restart process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to restart process
# 1  
Old 08-30-2012
Script to restart process

HI,

I am trying to write a scrip which would restart active process. This is what i have written till now.

Code:
[xmp@tswebptcadmin ~]$ xms show pr PRESE.*
NAME                            STATUS    ROLE  PID    RSTRTS  STARTED       MACHINE
-----------------------------------------------------------------------------------------
PRESENCE-STORE.1.tswebptcxmp1   Running   A     29002       0  Aug-27 20:58  tswebptcxmp1
PRESENCE-STORE.1.tswebptcxmp2   Running   S     16097       0  Aug-27 21:05  tswebptcxmp2
PRESENCE-STORE.2.tswebptcxmp1   Running   A     29003       0  Aug-27 20:58  tswebptcxmp1
PRESENCE-STORE.2.tswebptcxmp2   Running   S     16098       0  Aug-27 21:05  tswebptcxmp2

Code:
#!/bin/bash

#########################################################################################################
# Shellscript   :       radiusmon.sh - Monitoring radius start/stop accounting
# Version       :       V1.0
# Owner         :       Siddhesh Khavnekar <siddhesh.khavnekar@mobixell.com>
# Date          :       2012-08-30
# Category      :       Files Management
#########################################################################################################
# Description   :       This scipt will Monitor radius start/stop accounting and restart active PSE
#                       processes if reached threshold values
#########################################################################################################

ACTIVE_PSE_COUNT=`grep "Current number of Active Requests to the PSE" /home/xmp/bin/radstats_output.txt | awk '{print $NF}' | head -1`
ACTIVE_PSE_PROC=`xms show pr PRESENCE-STORE.* |awk '{print $3}'|grep "A"`

#Active PSE_COUNT
#-----------------
if [ $ACTIVE_PSE_COUNT -gt 200 ]; then
xms restart proc PRESENCE-STORE.1.tswebptcxmp1

fi

exit

Here if the value for ACTIVE_PSE_COUNT exceed beyond 200 then it should restart active process.

Here i want to restart active process which has value "A" under role, which i am not sure how to do it. Please advice.

-Siddhesh

---------- Post updated at 10:32 AM ---------- Previous update was at 10:11 AM ----------

Hi All,

Further to this.

Code:
#!/bin/bash

#########################################################################################################
# Shellscript   :       radiusmon.sh - Monitoring radius start/stop accounting
# Version       :       V1.0
# Owner         :       Siddhesh Khavnekar <siddhesh.khavnekar@mobixell.com>
# Date          :       2012-08-30
# Category      :       Files Management
#########################################################################################################
# Description   :       This scipt will Monitor radius start/stop accounting and restart active PSE
#                       processes if reached threshold values
#########################################################################################################

#/home/xmp/bin/radstats > /home/xmp/bin/radstats_output.txt
ACTIVE_PSE_COUNT=`grep "Current number of Active Requests to the PSE" /home/xmp/bin/radstats_output.txt | awk '{print $NF}' | head -1`
ACTIVE_PSE_PROC_1=`xms show pr PRESENCE-STORE.1.* |awk '{print $1 $3}' |grep "A" |tail -1`

#Active PSE_COUNT
#-----------------
if [ $ACTIVE_PSE_COUNT -gt 200 ]; then
xms restart proc $ACTIVE_PSE_PROC_1

fi

exit

Now what issue i m facing is the out of ACTIVE_PSE_PROC_1 is as below...

PRESENCE-STORE.1.tswebptcxmp1A

I do not want the last letter "A" here, because of which it does not reastar the process. Please advice.

Code:
[xmp@tswebptcadmin ~]$ ./radiusmon.sh
ERROR: No such process: PRESENCE-STORE.1.tswebptcxmp1A

-Siddhesh

Last edited by Franklin52; 08-30-2012 at 04:31 AM.. Reason: fixed code tags
# 2  
Old 08-30-2012
Hi

Code:
ACTIVE_PSE_PROC_1=`xms show pr PRESENCE-STORE.1.*  | awk '$3=="A"{print $1}' | tail -1`

Guru.
# 3  
Old 08-30-2012
Quote:
Originally Posted by Siddheshk
Code:
ACTIVE_PSE_COUNT=`grep "Current number of Active Requests to the PSE" /home/xmp/bin/radstats_output.txt | awk '{print $NF}' | head -1`

you use an treatment on every line but you took only the first line. It's more logical to put the head -1 before the awk treatement. Moreover the grep has the option "-m x" which stop reading file when the x patterns are found.

so the code should be :
Code:
ACTIVE_PSE_COUNT=`grep -m 1 'Current number of Active Requests to the PSE'  /home/xmp/bin/radstats_output.txt | awk '{print $NF}' `

Quote:
I do not want the last letter "A" here, because of which it does not reastar the process. Please advice.
Code:
ACTIVE_PSE_PROC_1=`xms show pr PRESENCE-STORE.1.* |awk '{print $1 $3}' |grep "A" |tail -1`

awk is a powerful tool, if you use a simple grep you must filter lines with awk :
For your code :
Code:
ACTIVE_PSE_PROC_1=`xms show pr PRESENCE-STORE.1.* |awk '$3 ~ /A/ {print $1 $3}' |tail -1`

# 4  
Old 08-31-2012
Hi,

I got that working. Now the problem is

Code:
/home/xmp/bin/radstats > /home/xmp/bin/radstats_output.txt
ACTIVE_PSE_COUNT=`grep "Current number of Active Requests to the PSE" /home/xmp/bin/radstats_output.txt | awk '{print $NF}' | head -1`
ACTIVE_PSE_PROC_1=`xms show pr PRESENCE-STORE.1.* |awk '$3=="A"{print $1}'|tail -1`
ACTIVE_PSE_PROC_2=`xms show pr PRESENCE-STORE.2.* |awk '$3=="A"{print $1}'|tail -1`

/home/xmp/bin/radstats > /home/xmp/bin/radstats_output.txt

It is working fine when i run in shell prompt, and redirects the output to home/xmp/bin/radstats_output.txt. But in script it is just not working. Please advice.

-SIddhesh

Last edited by Siddheshk; 08-31-2012 at 02:16 PM..
# 5  
Old 08-31-2012
In what way is it "not working"?

How is this shell script being run? Manually by you, or in cron?

Are you perhaps getting a different shell in the script than you do in your login?
# 6  
Old 08-31-2012
Hi,

i am not able to redirect the output of "radstat" command to a file i mentioned. i am running this script through cron.

here is the complete script.

Code:
#!/bin/bash

#########################################################################################################
# Shellscript   :       radiusmon.sh - Monitoring radius start/stop accounting
# Version       :       V1.0
# Owner         :       Siddhesh Khavnekar <siddhesh.khavnekar@mobixell.com>
# Date          :       2012-08-30
# Category      :       Files Management
#########################################################################################################
# Description   :       This scipt will Monitor radius start/stop accounting and restart active PSE
#                       processes if reached threshold values
#########################################################################################################

/home/xmp/bin/radstats > /home/xmp/bin/radstats_output.txt
ACTIVE_PSE_COUNT=`grep "Current number of Active Requests to the PSE" /home/xmp/bin/radstats_output.txt | awk '{print $NF}' | head -1`
ACTIVE_PSE_PROC_1=`xms show pr PRESENCE-STORE.1.* |awk '$3=="A"{print $1}'|tail -1`
ACTIVE_PSE_PROC_2=`xms show pr PRESENCE-STORE.2.* |awk '$3=="A"{print $1}'|tail -1`

#Active PSE_COUNT
#-----------------
if [ $ACTIVE_PSE_COUNT -gt 300 ]; then
xms restart proc $ACTIVE_PSE_PROC_1

#snmptrap -v 2c -c mobilewebproxy 10.201.1.99:162 '' 1.3.6.1.4.1.12702.9.10000.6 1.3.6.1.4.1.12702.9.10000  s "Current number of Active Requests to the PSE exceeded..Active PSE restarted!!"

fi

sleep 30

if [ $ACTIVE_PSE_COUNT -gt 300 ]; then
xms restart proc $ACTIVE_PSE_PROC_2
#snmptrap -v 2c -c mobilewebproxy 10.201.1.99:162 '' 1.3.6.1.4.1.12702.9.10000.6 1.3.6.1.4.1.12702.9.10000  s "Current number of Active Requests to the PSE exceeded..Active PSE restarted!!"

fi

exit

-Siddhesh
# 7  
Old 08-31-2012
Quote:
Originally Posted by Siddheshk
Hi,

i am not able to redirect the output of "radstat" command to a file i mentioned. i am running this script through cron.
As what user? Does that user have permission to write to that file?

Also, cron has a very minimal PATH. Add this just below the shebang: . /etc/profile which should get a more sane PATH set so it can find things like grep.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How do i restart a process if it fails?

Hi Guru's, I just want to have an idea on how to restart a particular step when it fails? SCENARIO we have plenty of steps such as the following below: Step 1 copy file from source to target location which is in a different server. Step 2 create initial and incremental process ... (4 Replies)
Discussion started by: reignangel2003
4 Replies

2. Shell Programming and Scripting

Monitor and restart UNIX process

Hi all, Tearing my hair out..! I have a requirement to monitor and restart a unix process via a simple watchdog script. I have the following 3 scripts that dont work for me.. script 1 (only produces 1 output if process is up or not)... (4 Replies)
Discussion started by: jonnyd
4 Replies

3. Emergency UNIX and Linux Support

Check hung process and restart

Hi all I have networker running on a RHEL 5.7 and over time it hangs. So the solution backup team proposed is to check if the process is hung, to stop and start it. Unfortunately for me, the rc script only allows three commands, start, stop and status (no restart option) so I managed to set... (15 Replies)
Discussion started by: hedkandi
15 Replies

4. Shell Programming and Scripting

Script to restart a process

I have written a script which checks for a file if that is being updated or not. If the files is not being updated then it will restart the process. #!/bin/sh DATE=`date +%Y%m%d%H%M%S` LOG_FILE=/var/xmp/log/XMP_* INCEPT=`ls -l $LOG_FILE |awk '{print $5}'` PROC=`xms show pr |grep -i... (3 Replies)
Discussion started by: Siddheshk
3 Replies

5. Shell Programming and Scripting

How to keep process running after apache restart.

I have posted this on the Web subforum but it seems that nobody knows to do this, maybe someone has a solution here. Thank you I have a PHP application that starts a couple of processes on the server...the problem is that if I restart apache those running apps will die. How can I start them... (1 Reply)
Discussion started by: valiadi
1 Replies

6. Web Development

How to keep process running after apache restart.

Hi, I have a PHP application that starts a couple of processes on the server...the problem is that if I restart apache those running apps will die. How can I start them in a way that they are not killed when I restart/stop apache ? $cmdstr = "nohup ".$config."/".$config."... (6 Replies)
Discussion started by: valiadi
6 Replies

7. Shell Programming and Scripting

restart process based on file

Hi all. I do have a script "startApp.sh" (app result is a file /opt/extract/appextract.txt) I have no problems with stopping app var1=`ps -ef | grep -v grep | grep MyApp | awk '{print $2}'` kill -9 $var1 What I want to achieve is: I start app, app is doing some extraction, after... (11 Replies)
Discussion started by: e-l-diablo
11 Replies

8. SuSE

Restart process

I have a process that gradually eats up memory, it's currently at 80.2% and slowing down the linux server > ps aux | grep SNMPME root 3129 0.0 80.2 3591752 2480700 ? Sl Feb13 5:04 /opt/nampe/lib/snmpme/SNMPME config/startup.xml Is there a command I can execute to restart this... (3 Replies)
Discussion started by: brendan76
3 Replies

9. Shell Programming and Scripting

need help to write script to check the process health and automatically restart it

I am working on a project, which need to constantly watch the process, and check its status, if it was dead, it should be restart automatically. Please kindly refer me to URL which teach how to write this kind of script, or service. Thanks. (1 Reply)
Discussion started by: dragondad
1 Replies

10. Shell Programming and Scripting

suspend/restart a process in shell script

Hi, I have a task that Im stuck on. I have an elementary script named 'myscript' that prints "the script is running" once a second. It runs for 27 seconds. I need to write a 2nd script that starts 'myscript' and takes a parameter '$1' for a number. my 2nd script then needs to pause myscript... (1 Reply)
Discussion started by: daneensign
1 Replies
Login or Register to Ask a Question