Need help in restarting process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in restarting process
# 1  
Old 02-25-2014
Need help in restarting process

Hi friends,

I have one unix command which is used to check the network status manually.
followig is the command
Code:
check_Network

this command give follwoing status
Code:
Network 1 is ok
    Network 2 is ok
    network 3 is ok
    network 4 is ok
    .
    .
    .
    .
    Network 10 is ok

Sometimes, command
Code:
check_Network

does not give any output and hanges at that moment. I need to press ctrl+c to come back to server command prompt
After that i restart network handler process by command
Code:
 restart ntework_all

After that command
Code:
check_Network

gives correct output as above.

Now, I want to automate this task by writting shell script.
1) Script should check netwok status ater regular interval (lets say 20 mins)
2) if command
Code:
check_Network

dont give any output and hanged. Then it should come out from hanged state (Similler to pressing ctrl+c) and restart network handler processes by
Code:
restart ntework_all

. and check network status again
3) After restart it should send mail to me saying "Network Handler has been restarted at <Time> "
# 2  
Old 02-25-2014
This might get you started - this version ignores any output from check_Network and only restarts if check_Network times out.

You could redirect the output of check_Network to a file and process the file at the bottom of this script checking for other conditions that require a restart.

I'd suggest running this script every 20min from cron rather that having it sleep and loop all the time.

Code:
TIMEOUT_SECS=20

command_timeout () {
   [ -d /proc/$check_pid ] || exit
   kill $check_pid
   wait $check_pid 2> /dev/null
   restart ntework_all
   echo "Network Handler has been restarted at $(date)" | mail -s "Network Handler" nakul_sh@mail.unix.com
}

check_Network > /dev/null 2>&1 &
check_pid=$!
parent_pid=$$

# Setup alarm for TIMEOUT_SECS that calls command_timeout
trap command_timeout SIGALRM
(sleep $TIMEOUT_SECS; kill -ALRM $parent_pid ) &
alarm_pid=$!

#wait for check_Network to finish
wait $check_pid 2> /dev/null

# We are back so cancel alarm
[ -d /proc/$alarm_pid ] && kill $alarm_pid


Last edited by Chubler_XL; 02-25-2014 at 04:43 PM.. Reason: Spelling
These 3 Users Gave Thanks to Chubler_XL For This Post:
# 3  
Old 02-27-2014
Thank YOu very much, But it have some problems

I run this script and seems that there are some issues with PID when it attempt to kill. It remain hanged after below output. I need to press ctrl+c to come out to command prompt.
Code:
Unix_buzz:>sh test123.sh
logout
Unix_buzz:>kill: 8182: The specified process does not exist.

But it seems that, timout factor is working fine. Because after 20 seconds,it immediately try to attempt the kill <PID>
I appreciate your help in this matter.
# 4  
Old 02-27-2014
My guess is you pressed ctrl+c before the 20 second timeout. If 20 seconds is too long (ie your inclined to press ctrl+c earlier that than) reduce the time, perhaps 5 seconds is a better fit for this command.
# 5  
Old 02-27-2014
No. i dont pressed ctrl+c before 20 seconds.. Seems that there are some issues with PID only.

is it possible to use any other method to get PID,instaead of using $! and $$ signs.
# 6  
Old 02-27-2014
No. What shell are you running this in?
# 7  
Old 02-27-2014
Of course this check_Network is a black box and could be spawning multiple other background processes, and it's one of those that's getting stuck.

When you manually clean up how do you find the PIDs ? Can you paste a ps listing of the stuck processes.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Process with S state(Interruptable) in RHEL and gives Advertise error after restarting/Killing the p

Hello, In our Production system one process is in S state(interruptible)and after killing and restarting the process gives 'advertise error'. This error goes after rebooting the Server. I have RHEL 5.9 (tikanga) OS in our server. We tried debugging the issue with the help of 'strace' command... (9 Replies)
Discussion started by: Rohits
9 Replies

2. SuSE

Restarting syslog-ng

Environment: SUSE 10.3 I made a configuration change in '/etc/syslog-ng/syslog-ng.conf' file in a server. An article found on web says "After the change '/etc/init.d/syslog-ng' should be restarted". But there is no 'syslog-ng' in /etc/init.d directory. What is syslog-ng or a... (4 Replies)
Discussion started by: JDBA
4 Replies

3. Solaris

Service is restarting too quickly

Hi guys, one of my services in solaris 10 is in maintenance mode. When I checked why, the reason is that the service is "restarting too quickly." # svcs -x svc:/application/management/snmpdx:default svc:/application/management/snmpdx:default (Sun Solstice Enterprise Master Agent) State:... (2 Replies)
Discussion started by: cjashu
2 Replies

4. UNIX for Dummies Questions & Answers

Restarting a process

Hi, How is it possible to restart only your process. I can get the process killed but I am not able to start it. For eg : i first did this ps -ef|grep _out --displays all the process with _out in the name then I killed kill -15 36044 -- process id. Now how can i start the same... (1 Reply)
Discussion started by: TH3M0Nk
1 Replies

5. Shell Programming and Scripting

Script for to kill the process Ids when restarting the unix server

Hi, I need a script to kill the process Ids for the user ABC. I prepared the following script after that while logging with user therough script i am not sure how to pass the user name and password.Can ou modify the script and help me out. #!/bin/bash for filesize in $(ls -ltr | grep... (4 Replies)
Discussion started by: victory
4 Replies

6. Programming

Restarting the program

Hi, I use gfortran to run the code. Some times I need to stop the program and restart it. On restarting I need to run the program from the beginning. Is there any script or option available to restart the program from where it stopped? This script/option will be immensely useful for... (2 Replies)
Discussion started by: rpd25
2 Replies

7. Solaris

server restarting

Hello people, My solaris server is rebooting, not sure how!!! Which log should I look in to? I checked /var/adm/messages and dmesg also. How do I check older dmesg logs? I checked lastlog and also ran the last command. Nothing useful pointing to why server rebooted. Also when server reboots I... (4 Replies)
Discussion started by: rcmrulzz
4 Replies

8. UNIX for Dummies Questions & Answers

Restarting the Spooler

:confused: Everytime our UNIXWARE 7 Server is restarted we also have to restart the spooler. If the spooler is not restarted, print jobs get stuck in the queu. Once restarted by using the following command lpstop and lpstart everything works fine. Does anyone have any ideas what could be causing... (0 Replies)
Discussion started by: Yorgy
0 Replies

9. Shell Programming and Scripting

Restarting a Crashed Process

Hello, I host a couple of Call of Duty gameing servers. There are some hackers who love the crash them. When they crash them it simply causes a segmentaion fault and kills the PID. I was wondering it you could help me write a script to simply restart the program after it has been crashed. The... (9 Replies)
Discussion started by: Phobos
9 Replies

10. UNIX for Dummies Questions & Answers

restarting a while loop

I have a monitoring script that checks on the content of an alert file, I'm doing some checks on weather I have already reported on the alert (there is one alert per file). If I find that the content is the same as before how can I stop and restart the loop until there is differences bewteen the... (5 Replies)
Discussion started by: nhatch
5 Replies
Login or Register to Ask a Question