Solved history not saved upon shutdown

obsigna

Profile disabled
When I have logged in via ssh, and simply do a regular exit later, all commands issued in the meantime are kept in the tcsh history – great, this is the expected behaviour. Now, when I instead shutdown -r now the machine, the commands since login are not kept anymore - bad, not expected. I cannot tell exactly when this started - perhaps after upgrading to 11.2 from 11.1 or even before, perhaps, 11.0 or 11.1. Anyway, I know storing the history upon shutdown did work in the more distant past.

Is this a bug? Please can anybody confirm this behaviour and confirm as well that this is not expected. In this case I am willing to file a PR.
 
It's not sshd(8) that saves your command history, it actually has nothing to do with SSH at all, it's a function of your shell.
 
It's not sshd(8) that saves your command history, it actually has nothing to do with SSH at all, it's a function of your shell.
OK, I know this. But this was not the question. The question is, whether this behaviour is expected or not. My shell is the default tcsh(1) one with all factory settings kept in place.

So, does your shell save the history on shutdown or does it not? And in case of yes it does, how did you manage it to do so? And in case it does not, is this a bug or is this expected?
 
So, does your shell save the history on shutdown or does it not?
As far as I'm aware, yes.

And in case of yes it does, how did you manage it to do so?
Absolutely nothing because the history is saved by default, all default ~/.cshrc files contain this:
Code:
        set history = 1000
        set savehist = (1000 merge)

Code:
       The history builtin command can print, store in a file, restore and
       clear the history list at any time, and the savehist and histfile shell
       variables can be set to store the history list automatically on logout
       and restore it on login.
From csh(1)
 
As far as I'm aware, yes.

Absolutely nothing because the history is saved by default, all default ~/.cshrc files contain this:
Code:
        set history = 1000
        set savehist = (1000 merge)
OK, thank you, I got the same in my ~/.cshrc files, and I never touched this. Now I added to that file the following, which sort of resolved my issue:
Code:
alias shutdown "history -M && /sbin/shutdown"
Anyway, I still think that this was not necessary in all the years before. Nevertheless, I mark this thread as solved.
 
Lets take a more methodical approach, does history work at all? I mean does it work normally if you stay logged in? And if you logout and back in? What are the permissions on ~/.history (the wrong permissions could prevent saving)? After a shutdown, is the entire history gone? Or just the last commands? It's possible one or more entries got corrupted, have you tried clearing the history ( history -c)?
 
Lets take a more methodical approach, does history work at all? I mean does it work normally if you stay logged in? And if you logout and back in? What are the permissions on ~/.history (the wrong permissions could prevent saving)? After a shutdown, is the entire history gone? Or just the last commands? It's possible one or more entries got corrupted, have you tried clearing the history ( history -c)?
Yes, it works on regular logout, and this was mentioned in the first sentence of the initial post:
When I have logged in via ssh, and simply do a regular exit later, all commands issued in the meantime are kept in the tcsh history – great, this is the expected behaviour. ...
 
Well, the only thing I can imagine happening is that you're not getting logged out when the system shuts down. But instead you're kicked out (process is killed, not stopped). Does shutting down take a long time? If I recall correctly there are some timers active when you shutdown. Normally services are properly stopped but if it doesn't stop in a timely manner the process is killed instead. That might explain why the history isn't saved.
 
SirDice, thank you. I learned now that this problem is on my site, and I need to investigate this further. As a temporary fix, I will keep calling history -M right before shutting down by the way of the alias in place.
 
.history stop working a long time ago, maybe since 10.1. After some days to weeks after a new installation, it MIGHT sometimes just start working but you can't count on that anymore.

I just build a good list (or two) and save it as backup before rebooting. I create a mountstart file and place it in /etc/rc.d/mountstart. It better to bring back only what you need. You can always add more lines by-way of the original .history file, and then resave that. I also might delete the old history and replace it using the commands inside my reboot and shutdown script. You have to play to know which way works best for you. I delete on reboot and replace at startup.

Code:
#! /bin/sh
# .................................
cp -prv /root/.history_backup /root/.history
sleep 2

/usr/bin/pkill dhclient;  sleep 2;             # something other
.
 
Back
Top