execute on ctrl-c before terminating previous command
I've been looking for a bandwidth monitor of some kind that will keep some kind of nicely readable log even after disconnection (compared to iptraf, bwm and some others).
All monitors I've seen were just too complicated for this task that should be rather simple (they require mysql, php and whatnot). So I did a simple script that does the job. I will post it on my blog if you want to see it, since that's about the first really useful thing I actually wrote myself in some kind of "computer" language (bash scripting this time). It's too simple of course, but yeah.
Anyway, the thing is that it uses "ifconfig ppp0" command to get the RX and TX data and I want it to run and log that data every time I terminate connection, but BEFORE it is actually terminated. If the script runs after connection is already gone and ppp0 interface is down already it is too late and there's nothing to log.
The script would first run "pppd call edge" as that's the connect command for me. That would establish ppp connection which can be terminated by "ctrl-c" command. What I want now is that when I do "ctrl-c" to terminate connection it first has to run "/etc/ppp/ppplog/ppptraf.sh" (my log script) and only then actually terminate connection.
I tried this with this command:
trap '/etc/ppp/ppplog/ppptraf.sh' SIGINT
but it is still too late as it runs that after ppp0 is already down.
So I'm looking for a way to run a command at "ctrl-c" but before "ctrl-c" terminates the previous command.. It's a bit tricky but I think it should be possible somehow, or at least something to that effect.