You are not logged in.

#1 2011-12-02 07:55:40

MikeW
Member
Registered: 2011-10-19
Posts: 66

Handling CTRL-C SIGINT in bash script

I am trying to trap ctrl-c and it doesn't work if a child process is running from the script (rsync for example). The process does exit but the parent script does not catch the signal, I suspect this has something to do with the child process running at the time. What I would like to do is perform some clean up / logging tasks if the user decides to abort the script via control-c.

Does anyone have any idea how handle this?

Offline

#2 2011-12-02 08:35:36

MikeW
Member
Registered: 2011-10-19
Posts: 66

Re: Handling CTRL-C SIGINT in bash script

Of course I manage to resolve this shortly after posting. A slightly different approach but it works.

- Added "set -e" to script.
- check exit code via "if [ $? -ne 0 ]; then"

Offline

Board footer

Powered by FluxBB