[opensuse] Any way to Save .bash_history command to file when HISTSIZE= is reached?
Listmates, Is there any way to Save .bash_history command to file when HISTSIZE= limit is reached? I would love to be able to hack whatever command removes entries from the .bash_history file and have it append that cli to something like history.sav so I could save old command lines. The problem is that I don't know where this code lives or whether it is even accessible to me. Anybody have any ideas? Thanks. -- David C. Rankin, J.D.,P.E. | openSoftware und SystemEntwicklung Rankin Law Firm, PLLC | Countdown for openSuSE 11.1 www.rankinlawfirm.com | http://counter.opensuse.org/11.1/small -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
----- Original Message -----
From: "David C. Rankin"
Listmates,
Is there any way to Save .bash_history command to file when HISTSIZE= limit is reached? I would love to be able to hack whatever command removes entries from the .bash_history file and have it append that cli to something like history.sav so I could save old command lines. The problem is that I don't know where this code lives or whether it is even accessible to me. Anybody have any ideas?
Thanks.
Klunky but you could probably have logrotate do it for you. I say klunky because I don't know off hand if logrotate has any syntax or globbing that would allow you to apply this to all users. So this example requires a seperate, mostly duplicate, stanza in a config file for each user whose history you want to maintain archives of. create a file /etc/logrotate.d/bash_history ---tof--- # Archive ~/.bash_history contents for some users # root /root/.bash_history { dateext rotate 99 size=+1024k notifempty missingok create 644 root root } # dcr /home/dcr/.bash_history { dateext rotate 99 size=+1024k notifempty missingok create 644 dcr users } ---eof--- There is nothing to restart for this to take effect. Once per day cron runs /etc/cron.daily/logrotate. The next time that happens, this new file will get read and the actions performed. Maybe change size larger or smaller. This is the idea not a tested and perfected recipe, so man logrotate to fine tune it. Oviously just add more copies of the dcr stanza to the same file for other users, edit the create line to match the user in question. Unless your reading of lograotate docs uncovers a nice globbing syntax to do all users. -- Brian K. White brian@aljex.com http://www.myspace.com/KEYofR +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Listmates,
Is there any way to Save .bash_history command to file when HISTSIZE= limit is reached? I would love to be able to hack whatever command removes entries from the .bash_history file and have it append that cli to something like history.sav so I could save old command lines. The problem is that I don't know where this code lives or whether it is even accessible to me. Anybody have any ideas?
Just make the history size limit bigger so it keeps whatever you want! If it gets too big, trim it by hand with vim or whatever. Haven't tested it but I'd be surprised if that had any ill effects. Cheers, Dave -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Listmates,
Is there any way to Save .bash_history command to file when HISTSIZE= limit is reached? I would love to be able to hack whatever command removes entries from the .bash_history file and have it append that cli to something like history.sav so I could save old command lines. The problem is that I don't know where this code lives or whether it is even accessible to me. Anybody have any ideas?
Thanks.
The history is saved in ./.bash_history. I believe that when you hit the size limit, the oldest commands are removed, rather than the entire list cleared, so if such a thing happened whenever the max number was reached, it would happen on every command, after you reached that limit. However, there's nothing to stop you from working with that file and copying it's contents etc. -- Use OpenOffice.org http://www.openoffice.org -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday, 2008-12-11 at 07:14 -0500, James Knott wrote:
The history is saved in ./.bash_history. I believe that when you hit the size limit, the oldest commands are removed, rather than the entire list cleared, so if such a thing happened whenever the max number was reached, it would happen on every command, after you reached that limit. However, there's nothing to stop you from working with that file and copying it's contents etc.
I /think/ the history is saved only when you exit bash. Till that moment, the current history is in memory only, and the file holds the previous session data. What happens when you have many bash sessions opened, I do not know. - -- Cheers, Carlos E. R. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) iEYEARECAAYFAklBDdEACgkQtTMYHG2NR9WW9gCaAuu3TgsACdVqM0dX7pzyo6PD 6bEAn2L1RlEGoWvGjMvOq5FPxRnQ692s =VI3o -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Carlos E. R. said the following on 12/11/2008 07:55 AM:
I /think/ the history is saved only when you exit bash. Till that moment, the current history is in memory only, and the file holds the previous session data.
That matches with my experience.
What happens when you have many bash sessions opened, I do not know.
Since I have many xterms open normally I run into this all the time. The literal answer is "last man down", but since I use the Konsole to support many sessions its more like a race condition when I sundown since I don't exit each shell and program. I rely on KDE to start them all up again when I log in again/restart and on Konsole to start the shells up in the working directories I was in at shut-down. Well, while that is true each shell in its own tab under console does not have the history it used to. They all have one history now, from the last shell shut down. I realise this isn't a "double-blind" parametrized scientific test, but I think it constituents adequate working evidence. -- "Engineers like to solve problems. If there are no problems handily available, they will create their own problems. Normal people don't understand this concept; they believe that if it ain't broke, don't fix it. Engineers believe that if ain't broke, it doesn't have enough features yet." - S. Adams -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thu, 11 Dec 2008, Carlos E. R. wrote:-
I /think/ the history is saved only when you exit bash. Till that moment, the current history is in memory only, and the file holds the previous session data.
It is kept in memory, unless you use "history -a" command to flush the in-memory history out to .bash_history[0]. By using "history -a" in once console, you can "import" the commands allows the used in that console into a previously opened console by using "history -n".
What happens when you have many bash sessions opened, I do not know.
When you close them, each consoles history is written to .bash_history and the oldest lines that go beyond the limit are lost. [0] And can be very useful if you paste something into the wrong console which would fill up your .bash_history with useless stuff. Regards, David Bolt -- Team Acorn: http://www.distributed.net/ OGR-NG @ ~100Mnodes RC5-72 @ ~1Mkeys/s SUSE 10.1 32 | | openSUSE 10.3 32b | openSUSE 11.0 32b | openSUSE 10.2 64b | openSUSE 10.3 64b | openSUSE 11.0 64b RISC OS 3.6 | TOS 4.02 | openSUSE 10.3 PPC | RISC OS 3.11 -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thu, December 11, 2008 09:10, David C. Rankin wrote:
Listmates,
Is there any way to Save .bash_history command to file when HISTSIZE= limit is reached? I would love to be able to hack whatever command removes entries from the .bash_history file and have it append that cli to something like history.sav so I could save old command lines. The problem is that I don't know where this code lives or whether it is even accessible to me. Anybody have any ideas?
I know it's not an answer to your question, but this helps to keep the bash history shorter: export HISTCONTROL=ignoredups or export HISTCONTROL=erasedups Unless of course you want to join that meme where people show off the top commands in their bash history: cut -f1 -d" " .bash_history | sort | uniq -c | sort -nr | head -n 30 user amedee: 169 sudo 41 ls 40 exit 20 man 17 cd 17 apt-cache 14 dig 14 curl 13 nano 13 elinks 8 su 8 screen 8 cat 7 phpize 7 irssi 7 hostname 6 slocate 6 locate 6 less 5 grep 4 whereis 4 wget 4 ps 4 df 4 ./apache_volume 3 uname 3 rm 3 ./apache_processes 3 ./apache_accesses 2 which user root: 51 exit 31 nano 30 ls 30 backup2l 29 tail 27 cd 25 iptables 25 ./hardlink.py 21 zgrep 16 man 15 aptitude 14 zcat 10 ps 10 nmap 10 grep 8 /etc/init.d/postfix 7 mc 7 crontab 7 apt-cache 6 /root/bin/hardlink.py 6 mailtail.sh 5 sudo 5 ./mailtail.sh 5 ip 5 cat 4 slocate 4 rm 4 echo 4 ./awstats.pl 3 `slocate -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 12 December 2008 08:43, Amedee Van Gasse wrote:
On Thu, December 11, 2008 09:10, David C. Rankin wrote:
Listmates,
...
I know it's not an answer to your question, but this helps to keep the bash history shorter:
export HISTCONTROL=ignoredups or export HISTCONTROL=erasedups
I exclude all one- and two-character commands, the job-control command "fg," all directory-changing commands (including my idiosyncratic directory stack commands, td, fd, tdu and tdd) as well as "exit" and "logout" from my history: export HISTIGNORE="?:??:td[ud]:fg *:exit:logout"
...
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 11 December 2008 00:10, David C. Rankin wrote:
Listmates,
Is there any way to Save .bash_history command to file when HISTSIZE= limit is reached? ...
Thanks.
Here's what I came up with after a message on this thread tipped me off about the "-a" option to BASH's built-in "history" command (the first block of environment settings were all I was using before these changes). The attached file is an excerpt from my .bashrc. Note the three variations on when to save new (since the most recent save) history entries. One is based on time intervals, the other on the number of commands added to the history since the previous save and the last, the one I'm using for now, updates the history file after each (elligible) command. In this variant, commands from my many shells will be interleaved across all shells (and I have many open and use them all frequently). It remains to be seen if I like that result, but it seems the best option.
-- David C. Rankin
Randall Schulz
David C. Rankin wrote:
Listmates,
Is there any way to Save .bash_history command to file when HISTSIZE= limit is reached? I would love to be able to hack whatever command removes entries from the .bash_history file and have it append that cli to something like history.sav so I could save old command lines. The problem is that I don't know where this code lives or whether it is even accessible to me. Anybody have any ideas?
Thanks.
Cleaning out my mail, I did want to post that I had found a very novel and solid approach to saving bash history eternally: http://www.debian-administration.org/articles/543 The article is "bash eternal history" and uses the PROMPT command to preserve all bash commands. Those Debian guys.... -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday February 6 2009, David C. Rankin wrote:
David C. Rankin wrote:
Listmates,
Is there any way to Save .bash_history command to file when HISTSIZE= limit is reached? I would love to be able to hack whatever command removes entries from the .bash_history file and have it append that cli to something like history.sav so I could save old command lines. The problem is that I don't know where this code lives or whether it is even accessible to me. Anybody have any ideas?
Thanks.
Cleaning out my mail,
I did want to post that I had found a very novel and solid approach to saving bash history eternally:
http://www.debian-administration.org/articles/543
The article is "bash eternal history" and uses the PROMPT command to preserve all bash commands. Those Debian guys....
Dude! I posted my own solution based on this concept (which I came up on my own) when this thread first came up! Check it out back in this thread on Dec. 23 at 06:25 (PST). It has an attachment, the script fragments for your ".bashrc". Admittedly, that was after the bulk of the conversation had ceased, but then, so is your posting today. This is the archive entry: http://lists.opensuse.org/opensuse/2008-12/msg01822.html
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Randall R Schulz wrote:
I did want to post that I had found a very novel and solid approach to saving bash history eternally:
http://www.debian-administration.org/articles/543
The article is "bash eternal history" and uses the PROMPT command to preserve all bash commands. Those Debian guys....
Dude! I posted my own solution based on this concept (which I came up on my own) when this thread first came up!
Check it out back in this thread on Dec. 23 at 06:25 (PST). It has an attachment, the script fragments for your ".bashrc". Admittedly, that was after the bulk of the conversation had ceased, but then, so is your posting today.
This is the archive entry: http://lists.opensuse.org/opensuse/2008-12/msg01822.html
Damn, I'm getting old. Ten years ago, I would never have forgotten 1 of the 24,601 emails in my openSuSE folder. I actually like your format better. Maybe Ginko will help the memory...;-) -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Saturday February 7 2009, David C. Rankin wrote:
Randall R Schulz wrote:
...
Dude! I posted my own solution based on this concept (which I came up on my own) when this thread first came up!
...
Damn, I'm getting old. Ten years ago, I would never have forgotten 1 of the 24,601 emails in my openSuSE folder. I actually like your format better. Maybe Ginko will help the memory...;-)
Is Ginko the one for you big brain or the one for your little brain? By the way, you should archive your openSUSE mailbox on a monthly basis. That keeps each archive mailbox and the main one pointed to by your filters under a few thousand messages, usually.
-- David C. Rankin
RRS -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Randall R Schulz wrote:
On Saturday February 7 2009, David C. Rankin wrote:
... Dude! I posted my own solution based on this concept (which I came up on my own) when this thread first came up!
... Damn, I'm getting old. Ten years ago, I would never have forgotten 1 of the 24,601 emails in my openSuSE folder. I actually like your
Randall R Schulz wrote: format better. Maybe Ginko will help the memory...;-)
Is Ginko the one for you big brain or the one for your little brain?
By the way, you should archive your openSUSE mailbox on a monthly basis. That keeps each archive mailbox and the main one pointed to by your filters under a few thousand messages, usually.
-- David C. Rankin
RRS
Now that's a trick I have got to learn. Can I do it in Thunderbird? -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Monday February 9 2009, David C. Rankin wrote:
Randall R Schulz wrote:
...
By the way, you should archive your openSUSE mailbox on a monthly basis. That keeps each archive mailbox and the main one pointed to by your filters under a few thousand messages, usually. ...
Now that's a trick I have got to learn. Can I do it in Thunderbird?
If you're asking about automating this process, as far as I know that's not even possible in KMail. It has an expiration mechanism that can move mail to an alternate folder, but that folder is fixed and expiration cannot, to my knowledge, be made to happen on a periodic basis. I just create sub-folders (anywhere from annually to monthly on an as-needed basis) and move old messages into it. I could probably script my style of archiving it in the shell, but I've never given that a thought. Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
* Randall R Schulz
If you're asking about automating this process, as far as I know that's not even possible in KMail. It has an expiration mechanism that can move mail to an alternate folder, but that folder is fixed and expiration cannot, to my knowledge, be made to happen on a periodic basis. I just create sub-folders (anywhere from annually to monthly on an as-needed basis) and move old messages into it.
I could probably script my style of archiving it in the shell, but I've never given that a thought.
I have seen such auto/backup/compress scripts on the mutt-users mail list. -- Patrick Shanahan Plainfield, Indiana, USA HOG # US1244711 http://wahoo.no-ip.org Photo Album: http://wahoo.no-ip.org/gallery2 Registered Linux User #207535 @ http://counter.li.org -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Patrick Shanahan wrote:
* Randall R Schulz
[02-09-09 15:16]: If you're asking about automating this process, as far as I know that's not even possible in KMail. It has an expiration mechanism that can move mail to an alternate folder, but that folder is fixed and expiration cannot, to my knowledge, be made to happen on a periodic basis. I just create sub-folders (anywhere from annually to monthly on an as-needed basis) and move old messages into it.
I could probably script my style of archiving it in the shell, but I've never given that a thought.
I have seen such auto/backup/compress scripts on the mutt-users mail list.
I'll mess around with the filter capabilities to see if I can come up with anything and post back if anything works. I also my crank up dovecot on my laptop and then try a few fetchmail scripts against my mailbox similar to what I do with fetchmail/spamassassin on the server. Interesting... -- David C. Rankin, J.D.,P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (10)
-
Amedee Van Gasse
-
Anton Aylward
-
Brian K. White
-
Carlos E. R.
-
Dave Howorth
-
David Bolt
-
David C. Rankin
-
James Knott
-
Patrick Shanahan
-
Randall R Schulz