LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 02-12-2014, 09:05 PM   #1
dchawk
LQ Newbie
 
Registered: Feb 2014
Posts: 4

Rep: Reputation: Disabled
Trap Commands


I have very little background using Linux and I am having a bit of an issue. I am trying to utilize the trap command to display a list of logged on users each time I log out. I was attempting to us trap ls/who exit. However, this does nothing for what I am trying to do. Any help would be greatly appreciated!!
 
Old 02-12-2014, 09:11 PM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please show your code? Just the trap, what signal it is being called on and what function you call the trap to perform.
 
1 members found this post helpful.
Old 02-12-2014, 10:12 PM   #3
dchawk
LQ Newbie
 
Registered: Feb 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Trap is brand new to me so I have no clue.
 
Old 02-12-2014, 10:27 PM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
I am not sure why you're using a trap command to do this. Assuming that you're running the bash shell, you can create a file called .bash_logout in your home directory and them put the ls and who commands in it. That file will be run every time you log out, and the output of those commands will be displayed in your terminal.
 
Old 02-12-2014, 11:20 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Quote:
Trap is brand new to me so I have no clue.
If this is the case I would say you need to hit up the man page and also any bash reference material on how to use trap ([url=http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_02.html]here[\url] is one such resource)

As mentioned above, you may be trying to use the wrong tool for the job, but you should at least read up on something prior to using it and asking questions which may be in general literature.
 
Old 02-13-2014, 10:05 PM   #6
dchawk
LQ Newbie
 
Registered: Feb 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Ok, at the prompt I entered :$bash
then at the 2nd prompt:$ trap who exit
lastly :$ exit (which provided a list of logged on users)
 
Old 02-13-2014, 11:51 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
So your issue is solved? Please mark as such from the Thread Tools
 
  


Reply



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
[SOLVED] BASH - Invoke commands when trap is activated worm5252 Programming 1 10-04-2011 04:54 PM
how to send snmp trap & recieve trap in C program minil Programming 3 07-10-2010 09:22 AM
Kernel trap (Fatal trap 12) m!k@EL *BSD 4 09-05-2007 11:58 PM
kill-trap basak Linux - Software 10 08-23-2006 05:38 PM
trap command for c? onnyloh Programming 3 09-13-2004 04:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:14 AM.

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
Open Source Consulting | Domain Registration