LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 05-11-2009, 07:58 PM   #1
sharp859
LQ Newbie
 
Registered: May 2008
Posts: 28

Rep: Reputation: 0
Regarding trap command


I have written service start stop shell script and it is running fine but only problem is while running if I hit CTRL-C after it comes out and if I run again it will not go through as previous run had created a temp file and it did not get removed.

So I need to call a function below like this it seems but it is throwing me an error some ting is missing.

settrap() {

trap 'print \'You hit control-C!\'' INT
rm -rf /tmp/dummy.startup

}

start () {

settrap ()

...
...
...

}

Please anybody can let me know how to trap the ctrl-c and once that ctrl-c hit while I am running it shold directly remove /tmp/dummy.startup file.



Thanks!
sharp
 
Old 05-11-2009, 08:35 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
See Example 29-6 here http://www.tldp.org/LDP/abs/html/debugging.html#EX76
 
  


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 to send snmp trap & recieve trap in C program minil Programming 3 07-10-2010 10:22 AM
what does the command do: trap ' ' 1 2 ? manohare Linux - General 2 03-02-2009 06:51 AM
SNMP Trap metallica1973 Linux - Networking 1 11-28-2007 10:14 AM
Kernel trap (Fatal trap 12) m!k@EL *BSD 4 09-06-2007 12:58 AM
trap command for c? onnyloh Programming 3 09-13-2004 05:06 AM


All times are GMT -5. The time now is 02:02 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration