Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bash shell problem

Status
Not open for further replies.

gmorton

Programmer
Dec 20, 2004
11
HK
Hi everyone

I've been trying all day to find out how to do the following and I'm having no luck. Any help would REALLY be appreciated.

I have a bash script that generates a log file, taking sar measurements at regular intervals in an endless loop. How can I assign a shortcut key that will call a function that I have written to do some cleen-up tasks before terminating. Control-c terminates my shell but, obviuosly, no clean-up is done. My function is quitter() and i've trieed the following, which doesn't work:

bind -x '"\C-q":quitter'

Thanks
Grant
 
look at trap, as you can direct the script to execute your stuff when your chosen keys are hit.
 
If you are running at regular intervals as a loop, why don't you cron the job? That way you can run your process with clean-up at whatever your intervals are. It's nice and tidy and built-in. You also don't need to be logged in.
 
As cdlvj says, the best way is trap.
Trap ^c and cleanup. That's pretty
standard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top