LinuxQuestions.org
Visit Jeremy's Blog.
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-10-2011, 10:05 PM   #1
stealth13
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Rep: Reputation: 0
How to copy bash history?


what command do i use to copy .bash_history to /tmp location?
 
Old 02-10-2011, 10:08 PM   #2
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Greetingz!

"cp ~/.bash_history /tmp" or if you want to do that automatically, put that command in a ".bash_logout" for the user in question.

If this post (or any other) is helpful, click "Yes" on the bottom right-corner of this post. If this post (or any other) also solves your problem, click "Thread Tools" at the top of the page and mark this as "[SOLVED]".
 
Old 02-10-2011, 10:09 PM   #3
stealth13
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by xeleema View Post
Greetingz!

"cp ~/.bash_history /tmp" or if you want to do that automatically, put that command in a ".bash_logout" for the user in question.

If this post (or any other) is helpful, click "Yes" on the bottom right-corner of this post. If this post (or any other) also solves your problem, click "Thread Tools" at the top of the page and mark this as "[SOLVED]".
how would I make it execute this command everytime a user logs in?
 
Old 02-10-2011, 10:15 PM   #4
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
What's the point of doing it when they log in? There'd be no history....
If you really wanted to copy the "old" history on login, just add that line to the top of their .bashrc or .bash_profile (one of those should be in their home dir).
 
Old 02-10-2011, 10:27 PM   #5
stealth13
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by xeleema View Post
What's the point of doing it when they log in? There'd be no history....
If you really wanted to copy the "old" history on login, just add that line to the top of their .bashrc or .bash_profile (one of those should be in their home dir).
I'm still not getting it. Lets say the username is mike what would i type after the root@mike ~]#
 
Old 02-10-2011, 10:53 PM   #6
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
Originally Posted by stealth13 View Post
I'm still not getting it. Lets say the username is mike what would i type after the root@mike ~]#
"cp ~mike/.bash_history /tmp"
 
Old 02-10-2011, 10:55 PM   #7
stealth13
LQ Newbie
 
Registered: Feb 2011
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by xeleema View Post
"cp ~mike/.bash_history /tmp"
Thanks! that worked, now what do i add to it to make it copy the bash history during login?
 
Old 02-11-2011, 05:05 AM   #8
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Okay, let's take this from the top;

How to Copy Bash History to /tmp
If any of the files listed here do not exist, create them. They can just have the one command in them, that's okay.

On Login:
Add the following to the user's .bashrc and/or .bash_profile
Code:
cp ~/.bash_history /tmp
On Logout:
Add the following to the user's .bash_logout
Code:
cp ~/.bash_history /tmp
Caveat #1: If you implement *both* copy-on-login and copy-on-logout, the /tmp/.bash_history file will be overwritten each time (not "appended to", the contents will be replaced)

Caveat #2: If you do either of copy-on-login and/or copy-on-logout for more than one user, they will all clobber the /tmp/.bash_history file on each login and logout.

Work-Around: Use the following command instead;
Code:
cp ~/.bash_history /tmp/`logname`-bash_history-`date +%Y_%m_%d-%H%M`
Downside: If you have this setup for a lot of users, you're going to start to fill /tmp (or the filesystem it's in).

If you're trying to get time/date information of when a certain user runs a certain command, then you need to read the bash manpage.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash history delete command from bash itself ashishag Linux - Software 6 05-02-2010 03:39 AM
copy history commands ZAMO Linux - General 4 01-04-2008 01:30 PM
bash history jasonnth Linux - Software 7 08-08-2006 01:35 AM
Download history and copy history? inverted.gravity Linux - Newbie 1 02-21-2006 12:31 PM
bash history slowly Linux - General 2 11-12-2004 11:35 AM


All times are GMT -5. The time now is 06:48 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration