- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- trap DEBUG
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-21-2010 02:10 AM
09-21-2010 02:10 AM
trap DEBUG
echo $- | /usr/bin/grep "i" > /dev/null 2>&1
if (( $? == 0 )); then
function history_to_syslog
{
typeset -i stat=$?
typeset cmd
cmd=$(command fc -ln -0)
Session:$$, Status:$stat Runned: $c
md"
MY_TTY=`/usr/bin/tty | /usr/bin/sed 's/\/dev\///'`
MY_ID=`/usr/bin/who | /usr/bin/grep "${MY_TTY}" | /usr/bin/awk '{print $1}'`
/usr/bin/logger -p daemon.notice -t "euid: ${LOGNAME} id: ${MY_ID} $$" Status ${
stat} PWD ${PWD} TTY=`tty` \'${cmd# }\'
}
trap 'history_to_syslog' DEBUG
fi
i use it to log all the commands to syslog.
If i run this script in a bash or ksh environment with HISTFILE=~/.bash_history it runs without a problem . if i change to /usr/bin/sh shell (change using su - root) halts after executing a command like it goes through an infinite debugging loop.
ie if i type ls is shows me the results but i have to press Ctrl-C to get a command prompt. If type a new command i get at the end a command prompt but after that the same problem occurs with additional commands.
- Tags:
- trap
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2010 04:09 AM
09-22-2010 04:09 AM
Re: trap DEBUG
in which users .profile? is it the roots .profile?
"change using su - root"
if you switch to root this way, you are getting its environment. Check if the function "history_to_syslog" is still there after switching to root:
# functions
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2010 09:06 PM
09-22-2010 09:06 PM
Re: trap DEBUG
When the profile is executed under a bash shell (. /.profile) logging works without a problem. If i change to sh either by su - root (it loads the profile), or just typing sh and then . /.profile from another session i get the above problem.
#trap -l
in bash shows me the signals
in sh shows me nothing
#trap
in both
trap -- history_to_syslog DEBUG
It seems in the case of sh it keeps debuging the commands inside the history_to_syslog function. And i don't know if there is a difference in trap command according to the shell used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2010 04:37 AM
09-23-2010 04:37 AM
Re: trap DEBUG
good point! there should be a difference, since the trap command is a shell builtin. I don't know the exact use of trap in the different shells, so consult the relevant manpage of your shell for more info.
According to a solaris man page (there's a separate man page for trap) the command might have a different name in a different shell:
NAME
trap, onintr - shell built-in functions to respond to
(hardware) signals
SYNOPSIS
sh
trap [ argument n [n2...]]
csh
onintr [-| label]
ksh
*trap [ arg sig [ sig2...]]
Unix operates with beer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2010 09:28 PM
09-23-2010 09:28 PM
Re: trap DEBUG
Is there another way to log all the shell commands in a file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2010 04:20 AM
09-24-2010 04:20 AM
Re: trap DEBUG
> it seems that DEBUG and ERR signals are not present in sh shell.
That is *not* true. The HP-UX 'sh' found as '/usr/bin/sh' or '/sbin/sh' is a POSIX shell documented as 'sh-posix(1)'. Look at those manpages, under the discussion of 'trap'.
Regards!
...JRF...