[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

bash script killed when child process killed

Posted on 2006-06-07
10
Medium Priority
?
1,230 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:kennym141282
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 43

Expert Comment

by:ravenpl
ID: 16854410
if You call
exec something # Your scripts is replced by something - it does not run anymore.

Can You bring the script here ?
0
 

Author Comment

by:kennym141282
ID: 16856859
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
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 16857024
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 51

Expert Comment

by:ahoffmann
ID: 16858896
(pon $PEER_NAME nodetach)
0
 

Author Comment

by:kennym141282
ID: 16859179
(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
 
LVL 43

Expert Comment

by:ravenpl
ID: 16859187
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
 

Author Comment

by:kennym141282
ID: 16859328
+ 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
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 1600 total points
ID: 16860721
I think interactive shells catch SIGTERM. Try this:
  trap "echo child signalled me" 15
0
 

Author Comment

by:kennym141282
ID: 16871694
I'll try this next week - just to say I'm not abandoning this question, just been a hectic day today :-)
0
 

Author Comment

by:kennym141282
ID: 16960673
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 23 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question