save history


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers save history
# 1  
Old 01-22-2009
Question save history

Hi there,
How can I add the current session command history to .bash_history?

During a session, I type several commands.

If I close my session, those commands are added to the file .bash_history.

But if my session crashes or just if I loose connection, those commands are lost.

Is there any way to regularly save the last typed commands?

Thanks for your help
Santiago
# 2  
Old 01-25-2009
Don't know of an automated way unless you write a script that does it. Guess you could write a script using this that is called at the start of a Bash session. Manual way is as follows.

Code:
history -w

# 3  
Old 01-25-2009
Thanks Lazydog, that's exactly what I was looking for.
Unfortunately, this command cannot be used in any script because I think a script creates a separate session. So doing history -w in a script does not append anything to the current .bash_history
# 4  
Old 01-25-2009
That's a strange one...I know you can turn the command history on/off and even increase/decrease the history size.

If I'm reading your question right you're saying during a normal session you can log back in to the server and your command history is still there...but if your session crashes for some reason...every command you entered during that session goes away? ...or does all of your command history goes away?

Is bash your default shell or is your default shell something else?

Try looking through this reference and see if maybe something isn't set right on your system... GNU Bash Reference Manual - Bash History Facilities

You might also try adding a user to the system with bash as the default shell and see if the same issue occurs.



*edit* I apologize if I'm reading into your issue incorrectly...late nite and not enough coffee...yet.
# 5  
Old 01-25-2009
bash is my default shell.
In case of crash, I only loose the commands entered during the session that crashed.
It looks like a normal behavior because cat .bash_history contains only commands typed during the previous sessions while history -a contains commands typed during the current session and history -w the concatenation of both.
Example:
Quote:
santiago@aldebaran:~$ ssh supernova
santiago@supernova:~$ cat .bash_history
echo hello world
santiago@supernova:~$ echo -e "this will appear in the history\nbecause this session will logout properly"
this will appear in the history
because this session will logout properly
santiago@supernova:~$ logout
Connection to supernova closed.
santiago@aldebaran:~$ ssh supernova
santiago@supernova:~$ cat .bash_history
echo hello world
cat .bash_history
echo -e "this will appear in the history\nbecause this session will logout properly"
santiago@supernova:~$ echo -e "this won't appear in the history\nbecause this session will crash"
this won't appear in the history
because this session will crash
santiago@supernova:~$ skill -KILL -u santiago
Connection to supernova closed.
santiago@aldebaran:~$ ssh supernova
santiago@supernova:~$ cat .bash_history
echo hello world
cat .bash_history
echo -e "this will appear in the history\nbecause this session will logout properly"
santiago@supernova:~$ echo -e "this will appear in the history\nbecause I'll save it before crash"
this will appear in the history
because I'll save it before crash
santiago@supernova:~$ history -w
santiago@supernova:~$ skill -KILL -u santiago
Connection to supernova closed.
santiago@aldebaran:~$ ssh supernova
santiago@supernova:~$ cat .bash_history
echo hello world
cat .bash_history
echo -e "this will appear in the history\nbecause this session will logout properly"
cat .bash_history
echo -e "this will appear in the history\nbecause I'll save it before crash"
history -w
santiago@supernova:~$
# 6  
Old 01-26-2009
I would say give it a try and see. You might be surprised. Smilie
# 7  
Old 01-26-2009
hi Lazydog,
what do you mean? I really tried it! This is no bullshit!
Santiago
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

The Great History of UNIX (1969-1999) | 30 Years of UNIX History | YouTube Video

I am pleased to announce this new video in 1080 HD for UNIX lovers honoring thirty years of UNIX history spanning from 1969 to 1999 presented in 150 seconds (two and a half minutes) in 1080 HD, celebrating the 50th anniversary of UNIX. The Great History of UNIX (1969-1999) | 30 Years of UNIX... (8 Replies)
Discussion started by: Neo
8 Replies

2. Shell Programming and Scripting

Save value from output of Corestat and save in a list for each core

I am trying to modify the "corestat v1.1" code which is in Perl.The typical output of this code is below: Core Utilization CoreId %Usr %Sys %Total ------ ----- ----- ------ 5 4.91 0.01 4.92 6 0.06 ... (0 Replies)
Discussion started by: Zam_1234
0 Replies

3. UNIX for Dummies Questions & Answers

History to Another file [local user history , but root access]

Hi all, My need is : 1. To know who , when , which command used. 2. Local user should not delete this information. I mean , with an example , i can say i have a user user1 i need to give all the following permissions to user1, : a. A specific directory other than his home... (1 Reply)
Discussion started by: sriky86
1 Replies

4. UNIX for Dummies Questions & Answers

The history command: See other users command history

Can anyone tell this: If two users are logged into the same server from different locations. Is there a way to see the history command of the other user? I tried the history command, but it is showing me only the commands I used. Thanks in advance for your help. Iamnew2solaris (1 Reply)
Discussion started by: iamnew2solaris
1 Replies

5. UNIX for Advanced & Expert Users

History to Another file [local user history , but root access]

Hi all, My need is : 1. To know who , when , which command used. 2. Local user should not delete this information. I mean , with an example , i can say i have a user user1 i need to give all the following permissions to user1, : a. A specific directory other than his home... (3 Replies)
Discussion started by: linuxadmin
3 Replies

6. UNIX for Dummies Questions & Answers

How to review the history and the commands that has been done in this history?

Hello every body, Kindly inform me How Do i find out the time I executed a command previously on UNIX Solaris?? To be more specific and more clear about what i want to know is that I want a command the enables me to know the history and which command i run at this history/time. FYI I used... (5 Replies)
Discussion started by: ahmedamer12
5 Replies

7. Shell Programming and Scripting

Save cURL verbose output to file or do it like browser "save as.."

hi there ! i have exactly the same problem like this guy here https://www.unix.com/shell-programming-scripting/127668-getting-curl-output-verbose-file.html i am not able to save the curl verbose output.. the sollution in this thread (redirecting stderr to a file) does not work for me.... (0 Replies)
Discussion started by: crabmeat
0 Replies

8. UNIX for Dummies Questions & Answers

Using history of commands to save typing?

Hi, How do I add a history function to my shell? What I mean is if I have used the command: xemacs file.tex, I'd like to be able to type 'x' then use the arrow keys and go through all the commands I've done starting with an 'x'. Thanks! (3 Replies)
Discussion started by: pmasterkim
3 Replies
Login or Register to Ask a Question