bash script killed when child process killed

I have a bash script which calls "pon $PEER_NAME nodetach" to initiate a PPTP connection to a client.

Once the connection comes up an ip-up script runs, does some stuff then calls "poff $PEER_NAME". poff successfully terminates pppd but it also kills my bash script (which I don't want nor expect).

The bash script returns an exit code of 143 (I know by running it by hand that pon $PEER_NAME nodetach returns 16).

I've tried various forms of calling pon from my bash script, including:

pon $PEER_NAME nodetach
exec pon $PEER_NAME nodetach
bash pon $PEER_NAME nodetach
source $(which pon)

Question worth 400 points for a fast answser!
kennym141282Asked:
Who is Participating?
 
Duncan RoeConnect With a Mentor Software DeveloperCommented:
I think interactive shells catch SIGTERM. Try this:
  trap "echo child signalled me" 15
0
 
ravenplCommented:
if You call
exec something # Your scripts is replced by something - it does not run anymore.

Can You bring the script here ?
0
 
kennym141282Author Commented:
The relevant section of the bash script is:-

# Try to bring the tunnel up repeatedly
RETRY_COUNTER=0
while [ $RETRY_COUNTER -lt $RETRY_COUNT ]; do
    echo "Running..."
    pon $PEER_NAME nodetach
    echo "Done!"
    # More stuff here that isn't important
done

# And the output is (run with set -x):-
+ RETRY_COUNTER=0
+ '[' 0 -lt 5 ']'
+ echo Running
Running
+ pon PEER nodetach
Using interface ppp0
Connect: ppp0 <--> /dev/pts/1
MPPE 128-bit stateless compression enabled
local  IP address 10.0.9.0
remote IP address 10.0.0.1
Terminating on signal 15
Connect time 1.1 minutes.
Sent 1124 bytes, received 9289 bytes.
MPPE disabled
Terminated    <--- BASH SCRIPT KILLED! :-(
elzar:~# Connection terminated.
tcflush failed: Input/output error
Modem hangup

Notice that the echo "Done!" line never gets executed since the script is terminated when the ip-up script kills pppd (via poff PEER).

I'm wanting to grab the exit code of pon and process it and etc...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Duncan RoeSoftware DeveloperCommented:
Bizarre. Your script doesn't by any chance include "set -e" early on does it? Could pon be sending a signal to its parent? Exit code 143 = signal 15 (SIGTERM)
0
 
ahoffmannCommented:
(pon $PEER_NAME nodetach)
0
 
kennym141282Author Commented:
(pon $PEER_NAME nodetach)

Didn't help - did exactly the same thing.

As for 'set -e' - I thought of that and added an explicit set +e just to be sure.

It's just, odd. I can't think of any other way of describing it, though "Bizarre" fits nicely too. :-)
0
 
ravenplCommented:
for to check if duncan_roe is right, try adding in the beggining of the script
trap "echo exiting due to child failure" ERR
0
 
kennym141282Author Commented:
+ trap 'echo exiting due to child failure' ERR
+ RETRY_COUNTER=0
+ '[' 0 -lt 5 ']'
+ echo Running
Running
+ pon PEER nodetach
Using interface ppp0
Connect: ppp0 <--> /dev/pts/0
MPPE 128-bit stateless compression enabled
local  IP address 10.0.9.0
remote IP address 10.0.0.1
Terminating on signal 15
Connect time 1.1 minutes.
Sent 1000 bytes, received 1716 bytes.
MPPE disabled
Terminated
elzar:~# Connection terminated.
tcflush failed: Input/output error
Modem hangup
0
 
kennym141282Author Commented:
I'll try this next week - just to say I'm not abandoning this question, just been a hectic day today :-)
0
 
kennym141282Author Commented:
Ok finally got back to this...

duncan_roe's comment with trap "echo child signalled me" 15 allowed the script to not be killed (and it indeed echo'd out that text).

I'm going to ahead an accept duncon_roe's comment as an answer.

Thanks to everyone for their help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.