- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Exiting from a Shell Script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2003 01:43 AM
09-14-2003 01:43 AM
Exiting from a Shell Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2003 01:55 AM
09-14-2003 01:55 AM
Re: Exiting from a Shell Script
I think you'll need to find out what signal Ctrl-X is sending. Use :
# stty -a
from the users shell. You can then map this to the trap number using :
# kill -l
Add this to your shell script trap and hopefully this will work.
cheers,
James.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2003 05:48 AM
09-14-2003 05:48 AM
Re: Exiting from a Shell Script
1. vi /usr/include/sys/signal.h
2. search for ???signal numbers???
trap '
<2nd line of script>
etc.
The most common signals to trap are 1,2,3,9,11,14,15
On 10.20, the signal numbers are:
/* Signal numbers */
# define _SIGHUP 1 /* floating point exception */
# define SIGINT 2 /* Interrupt */
# define _SIGQUIT 3 /* quit */
# define SIGILL 4 /* Illegal instruction (not reset when
caught) */
# define _SIGTRAP 5 /* trace trap (not reset when caught) */
# define SIGABRT 6 /* Process abort signal */
# define _SIGIOT SIGABRT /* IOT instruction */
# define _SIGEMT 7 /* EMT instruction */
# define SIGFPE 8 /* Floating point exception */
# define _SIGKILL 9 /* kill (cannot be caught of ignored) */
# define _SIGBUS 10 /* bus error */
# define SIGSEGV 11 /* Segmentation violation */
# define _SIGSYS 12 /* bad argument to system call */
# define _SIGPIPE 13 /* write on a pipe with no one to read it */
# define _SIGALRM 14 /* alarm clock */
# define SIGTERM 15 /* Software termination signal from kill */
# define _SIGUSR1 16 /* user defined signal 1 */
# define _SIGUSR2 17 /* user defined signal 2 */
# define _SIGCHLD 18 /* Child process terminated or stopped */
# define _SIGCLD _SIGCHLD /* death of a child */
# define _SIGPWR 19 /* power state indication */
# define _SIGVTALRM 20 /* virtual timer alarm */
# define _SIGPROF 21 /* profiling timer alarm */
# define _SIGIO 22 /* asynchronous I/O */
# define _SIGPOLL _SIGIO /* for HP-UX hpstreams signal */
# define _SIGWINCH 23 /* window size change signal */
# define _SIGWINDOW _SIGWINCH /* added for compatibility reasons */
# define _SIGSTOP 24 /* Stop signal (cannot be caught or ignored) */
# define _SIGTSTP 25 /* Interactive stop signal */
# define _SIGCONT 26 /* Continue if stopped */
# define _SIGTTIN 27 /* Read from control terminal attempted by a
member of a background process group */
# define _SIGTTOU 28 /* Write to control terminal attempted by a
member of a background process group */
# define _SIGURG 29 /* urgent condition on IO channel */
# define _SIGLOST 30 /* remote lock lost (NFS) */
# define _SIGRESERVE 31 /* Save for future use */
# define _SIGDIL 32 /* DIL signal */
# define _SIGXCPU 33 /* CPU time limit exceeded (setrlimit) */
# define _SIGXFSZ 34 /* CPU file size limit exceeded (setrlimit) */
Hope this helps!
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2003 02:31 AM
12-20-2003 02:31 AM
Re: Exiting from a Shell Script
trap `dfrag |echo "trapping signal 15 for PID dfrag" 15`
It started dfrag but I did not see my trap displayed? Is this corect? How do I trap this PID of dfrag?
NOTE : dfrag is an executable
thanks
derek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2003 03:51 AM
12-20-2003 03:51 AM
Re: Exiting from a Shell Script
trap [action condition]
you should be doing something like this
#set trap
trap "print \"caught signal\"" INT QUIT TERM
dfrag
#unset trap
trap - INT QUIT TERM
# INT QUIT TERM are signal numbers 2,3, and 15
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2003 07:25 AM
12-20-2003 07:25 AM
Re: Exiting from a Shell Script
# Ignore HUP, INT, QUIT now.
trap "" 1 2 3
...
trap 1 2 3
The first trap disables trap signals 1 2 and 3 and then at the end, re-enables the traps. So during /etc/profiel, CTRL-C has no effect and is ignored. Now if you want your script to exit, there are two choices: make the script the user's shell, then an exit leaves the session completely. Otherwise, you'll need to exec the shell script so that the script is run by the current shell, not a subshell.
Bill Hassell, sysadmin