Customize history shell

Customize history shell

Post by Andrea Gandugli » Wed, 28 Jun 2006 04:18:08



How can I customize history shell? I need to create a .custom_history file
that contains:

data time $SSH_CLIENT command(s)

I'm trying to re-define $SHELL var into .bashrc with a custom file that
write custom info into .custom_history before execute command, but it
don't works.

[.bashrc]
SHELL=$HOME/bin/mash

[$HOME/bin/mash]
#!/bin/bash
DATE=$(date +%Y-%m-%d %H:%M:%S)
SSHINFO=$(echo $SSH_CLIENT | awk '{print $1}')

How can I do it?

 
 
 

Customize history shell

Post by Chris F.A. Johnso » Wed, 28 Jun 2006 06:33:24



> How can I customize history shell? I need to create a .custom_history file
> that contains:

> data time $SSH_CLIENT command(s)

> I'm trying to re-define $SHELL var into .bashrc with a custom file that
> write custom info into .custom_history before execute command, but it
> don't works.

> [.bashrc]
> SHELL=$HOME/bin/mash

> [$HOME/bin/mash]
> #!/bin/bash
> DATE=$(date +%Y-%m-%d %H:%M:%S)
> SSHINFO=$(echo $SSH_CLIENT | awk '{print $1}')


> How can I do it?

   Set HISTTIMEFORMAT and a timestamp will be generated in your
   history file.

--
   Chris F.A. Johnson, author              <http://cfaj.freeshell.org>
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
   ===== My code in this post, if any, assumes the POSIX locale
   ===== and is released under the GNU General Public Licence

 
 
 

1. bash history customizing

forgive me if this has been asked before, im a newbie to this
newsgroup, and a google search couldnt find me exactly what im looking
for.

I really like my bash history facility, so much so that i have about
the maximum size set to 50000 and my HISTIGNORE list is rather large.

I found a way to stop history from remembering duplicate commands
(HISTCONTROL=ignoredups), which helps, but I want it to go further.

For one thing, I would like to prevent invalid commands from being
saved in my history. (not terminated commands, if possible, just
invalid ones, i.e. "cd $HOMEE" or "emax afile.txt")
Does anyone know of a good way to do this?

I also want to eliminate all duplicate commands in my history file,
but I want to keep the most recent duplicate only.
In other words if my history contains this...

1 cd $HOME
2 vi somefile.txt
3 cp somefile anotherfile
4 exit
5 cd $HOME
6 vi somefile
7 exit

I would like it to become

1 cp somefile anotherfile
2 cd $HOME
3 vi somefile
4 exit

This way, over time most of my useful, regularly used commands would
rise to the top, while the useless ones would sift to the bottom of
the list. (for eventual manual purging?)

The obvious way is via a sort -u, but this sorts alphabetically which
is totally not what I want.

The only way I can thionk of doing this is via a regularly run script,
is ther a better way of doing it?
Surely im not the only one who has thought of this before...

2. Solaris in.ftpd and directory group sticky bit inheritance

3. Process history under C-shell and Bourne shell

4. CERN 3.0: Any cache logs ?

5. Customized installation with customized comps file...

6. How to configure my Windows keys in Gnome v1.4?

7. Flushing history to .history prior to logout?

8. Iomega ZIP-Drive

9. bash history -s appends to the previous history

10. source code for the history mechanism that is provided by the csh command shell

11. BORN Shell history

12. How to edit the history file in Korn Shell

13. Date stamping commands in the shell command history file