Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

after the kill statement the script prints "Terminated" and the following lines never get executed:

#!/bin/bash

kill -9 `ps -ef | grep MailSender | grep -v grep | awk '{print $2}'`
echo starting
./MailSender

I have even tried to add set +e at the beginning but it still exits after kill.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Does the name of your script include MailSender? Try changing it, if so. Also, use pkill -9, it'll be cleaner:

#!/bin/bash

pkill -9 MailSender
echo starting
./MailSender
share|improve this answer
3  
Why not using pkill directly? :) (And - why -9? 'kill -kill' is so harmful...) –  Michuelnik Jun 14 '12 at 16:28
    
Guess I didn't optimise the code far enough, thanks :-) I'm hoping this is a last-resort script, so I didn't argue with the use of SIGKILL. Admittedly, I have used to kill processes when they would lockup but still absort SIGTERMs so there might still be a genuine use to script it. –  Jay Jun 14 '12 at 16:31
    
pkill doesnt work, I guess its because MailSender is an argument: /opt/mono-2.10/bin/mono /etc/sender/MailSender.exe –  SCL Jun 14 '12 at 16:33
    
And if you are under Solaris, don't use killall, which would work the same as pkill under Linux but literally kill all processes under Solaris. –  SvW Jun 14 '12 at 16:34
1  
@Dawkins You should be able to do pkill -f "Mailsender.exe" –  cjc Jun 14 '12 at 17:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.