- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- capture exit staus
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
03-16-2003 08:01 AM
03-16-2003 08:01 AM
hmm....
like clear out temp files for the user,
unset VAR's
run different command in the background
etc.
in KSH, for csh users I use .logout
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 08:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 08:18 AM
03-16-2003 08:18 AM
Re: capture exit staus
tell me more about this trap thing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 08:33 AM
03-16-2003 08:33 AM
Re: capture exit staus
set -u
export PATH=/usr/bin
export MYNAME=$(uname -n)
export TEMPPATH=/var/tmp/$MYNAME.$$
export TEMPFILE1=$TEMPPATH/temp1
trap 'rm -f $TEMPPATH' 0 1 2 3 15
So: set -u prevents undefine variables from being used (can be a problem with misspelled variables)
PATH is redfined inside the shell script to prevent improper $PATH locations from being used.
TEMPPATH specifies a directory for all temp files that is unique to this specific shell script.
TEMPFILE1 defines one (of possbily many) temp files.
trap defines what action to take if the script terminates for any reason (including a normal exit, trap ... 0). You can create multiple traps for each signal (ie, kill -15, etc).
Now if this is an action to be taken in the login shell, then put the:
trap 'series of tasks' 0
in .profile for each user. Be sure to put the trap near the top of the script so it will be effective even during .profile's execution. NOTE: there is no need to unset VAR's when a shell exits, whether it is the login shell or a shell script. These VARs are stored in the shell's data area so when teh shell exits, everything is returned to the kernel for reuse. AS far as temp files for each user, that will be quite difficult to code since users might ctreate temp files anywhere they can write.
trap is used in /etc/profile to PREVENT the normal action for a kill signal such as CTRL-c (ie, kill -15). The trap command in /etc/profile at the top of the script essentially says: ignore all unexpected kill signals (kill -9 cannot be trapped) and do nothing. The trap at the end of /etc/profile is REQUIRED to turn normal behavior for these trap signals.
The trap commnand is part of all POSIX shells such as ksh and HP's POSIX shell (and bash, etc).
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 08:46 AM
03-16-2003 08:46 AM
Re: capture exit staus
can I use
trap '
??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 09:35 AM
03-16-2003 09:35 AM
Re: capture exit staus
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 09:40 AM
03-16-2003 09:40 AM
Re: capture exit staus
#!/bin/ksh
trap delem 0 1 2 3 15
TMPFILE=/tmp/myfile.$$
touch $TMPFILE
function delem {
date; rm -rf $TMPFILE 2>/dev/null; exit 1
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 09:52 AM
03-16-2003 09:52 AM
Re: capture exit staus
I am okay from here on now.
what is the CTRL C code if I want to watch for it? to not break the script??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 11:45 AM
03-16-2003 11:45 AM
Re: capture exit staus
sleep 10
then press the CTRL key and also press c at the same time, sleep will be terminated. The trap command senses this condition and takes the action specified in the trap statement. The other numbers given in the above examples (0 1 2 3 15) are other kill sugnals. To get a quick reference, type:
kill -l
and look at the man pages for:
man kill
man signal
Bill Hassell, sysadmin