The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ctrl-M at end of each line navi Shell Programming and Scripting 3 06-04-2008 12:09 AM
how to enable Ctrl + C in ksh dradhzn Shell Programming and Scripting 0 05-01-2006 07:32 PM
Disable ctrl-c,ctrl-d,ctrl-d in ksh script wtofu AIX 6 06-29-2005 01:41 PM
my ctrl+c doesn't work yankee428 UNIX for Dummies Questions & Answers 3 06-02-2005 10:35 AM
Script ctrl+c newtounix UNIX for Dummies Questions & Answers 1 03-19-2001 01:23 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-02-2006
Registered User
 

Join Date: Apr 2006
Posts: 33
Catching ctrl-C or ctrl-D

Hi there,
I'm using HP-UX 11 machine. I am running a script, thats gonna take a long time to execute. When I press ctrl-c to come out of my script, I have to catch that signal(ctrl-c) and display that ctrl-c had been pressed. How can I do it.


Thanks in advance
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-02-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
Read about trap in man bash/ksh. And then search this forum with the keywords 'trap signal'
Reply With Quote
  #3 (permalink)  
Old 05-02-2006
Registered User
 

Join Date: Mar 2006
Location: Nashville
Posts: 77
I use this trap in one of my install scripts. So if someone hits control -c when my install script is running, it prints that the install was aborted.

USER=$(logname)
LOG=/tmp/sample_install.log
#Set Trap
trap 'print "Install was aborted in the middle of the install by $USER" | tee -a $LOG; exit 1' 1 2 15

Trap based on the signals. I think there is a total of 31 or so. The above line traps for signal 1, 2, and 15.

1 = HUP
2 = INT
15 = TERM

*The output of this command may differ slightly with operating systems.

PS..Buy the book, "Unix Shells by example" Ellie Quigley

-X
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0