Register
It is currently Sun Apr 20, 2014 2:16 am

kill a script that launches external process


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Fri Nov 26, 2010 6:33 am   

Joined: Fri Nov 26, 2010 6:13 am
Posts: 1
Hi All,
I'm doing a script called script1, that run a external bin called process1. If process1 ends with a particular message I need to re-run process1 with a new parameter.
I do this and it worked but now I have to launch script1 from another called script2.
Script2 has to kill script1 after a timeout by a SIGTERM, I have the problem that process1 doesn't die.

I can't change Script2, I can only modify script1.

This is my code
script1
Code:
#!/bin/bash

ABSPATH=`readlink $0` #resolves symbolic link, if any
if [ -z "$ABSPATH" ]; then ABSPATH=$0; fi
ABSPATH=$(cd `dirname $ABSPATH` && pwd) #resolves relative paths

PROCESS1_HOME=$ABSPATH
echo $PROCESS1_HOME
export LIB_PATH=$PROCESS1_HOME/lib

CMD_LINE="$PROCESS1_HOME/process1"
TMP_OUT=/tmp/tmp_out

CMD_LINE="$CMD_LINE $@"

$CMD_LINE |tee $TMP_OUT

check=`cat $TMP_OUT | grep "rerun it" | wc -l`

if [ "$check" -eq 1 ]; then
    CMD_LINE="$CMD_LINE -new_param"
    $CMD_LINE |tee $TMP_OUT
fi
#cat $TMP_OUT
rm $TMP_OUT
exit 0


Thanks!


Top
 Profile  
 PostPosted: Fri Nov 26, 2010 4:19 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
You can set
Code:
trap 'killall -9 process1' SIGTERM

or something similar.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP