LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-06-2010, 02:31 AM   #1
dctw
LQ Newbie
 
Registered: Oct 2009
Posts: 27

Rep: Reputation: 0
Ignore/Disable Ctrl-C (SIGINT) in a shell script


How do I write my trap statement in shell script to ignore SIGINT.
Reason being is that the script is used to update records in database. I want to avoid inconsistency in database when user presses Ctrl-C ...

The result should be
1. Totally ignore Ctrl-C (SIGINT) when user presses Ctrl-C
2. Continue with the rest of processing
 
Old 01-06-2010, 03:35 AM   #2
choogendyk
Senior Member
 
Registered: Aug 2007
Location: Massachusetts, USA
Distribution: Solaris 9 & 10, Mac OS X, Ubuntu Server
Posts: 1,197

Rep: Reputation: 105Reputation: 105
trap is what you want.

see, for example, http://linuxdevcenter.com/pub/a/linux/lpt/44_12.html.
 
Old 01-06-2010, 05:51 AM   #3
ForzaItalia2006
Member
 
Registered: Dec 2009
Location: Walldorf, Germany
Distribution: (X)Ubuntu, Arch, Gentoo
Posts: 205

Rep: Reputation: 67
Hey,

try this:

trap "" 2

The number 2 stands for SIGINT (CTRL+C). This should then ignore the interrupt, at least bourne shell (sh) and bash :-)

- Andi -
 
Old 01-11-2010, 03:30 AM   #4
dctw
LQ Newbie
 
Registered: Oct 2009
Posts: 27

Original Poster
Rep: Reputation: 0
It does not work..
The database still interrupts the operation when I press Ctrl-C

I think it is due to the handling within the database software, not on the shell ....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how does ctrl+c works with SIGINT in redhat linux saikasavar Linux - General 1 07-16-2007 05:09 AM
Making a shell script to enable/disable apache/mysql Lazy Foo' Programming 2 01-27-2006 10:07 AM
Disable Ctrl+Alt+Fn lukeprog Ubuntu 5 12-22-2005 03:30 PM
catch Ctrl-C from shell script gecoool Programming 4 10-27-2005 02:19 AM
Disable ctrl - c for users quack322 Programming 5 08-22-2004 11:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration