1834606 Members
3951 Online
110069 Solutions
New Discussion

Script that kill itself

 
SOLVED
Go to solution
Ricardo Bassoi
Regular Advisor

Script that kill itself

Hi All,

Is there a way to create a script1 that call another one ( script2 ) and after 20 seconds kill both ?

Tks..
If you never try, never will work
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Script that kill itself

Hi:

Sure, do launch the second script in the background; note its PID; sleep 20-seconds; issue a 'kill PID'; and exit. Something like:

#!/usr/bin/sh
$HOME/script2 &
PID=$!
sleep 20
kill $PID
exit 0

Regards!

...JRF...
someone_4
Honored Contributor

Re: Script that kill itself

Hi How about ..

#!/usr/bin/sh
/home/user/script2 &
sleep 20
pid_var=`ps -ef | grep script2 | grep -v grep | awk '{print $2}'`
kill -9 $pid_var


Richard
MANOJ SRIVASTAVA
Honored Contributor

Re: Script that kill itself

Hi Ricardo

try this

#!/usr/bin/ksh
/home/script1
/home/script2

A= `ps -ef | grep script1 | grep -v grep | awk '{print $1}'
B= `ps -ef | grep script2 | grep -v grep | awk'{print $1}'
C==`ps -ef | grep script1 | grep -v grep | awk '{print $2}'

sleep 20

kill -9 $A $B $C


and this should be good to go.


Manoj Srivastava

A. Clay Stephenson
Acclaimed Contributor

Re: Script that kill itself

Hi:

Just as another way to do this using a Perl signal handler (among other more traditional methods), please see this thread:

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x2c4daf48a9e5d5118ff40090279cd0f9,00.html
If it ain't broke, I can fix that.
Ricardo Bassoi
Regular Advisor

Re: Script that kill itself

It works !!!
Thank to all for the help...
If you never try, never will work