Sponsored Content
Full Discussion: Comande historique
Operating Systems AIX Comande historique Post 99974 by Garry_Garrett on Wednesday 22nd of February 2006 07:21:41 PM
Old 02-22-2006
How your shell history is kept depends upon your shell (sh, csh, ksh, etc.). You are probably using Korn shell, which defaults to using .sh_history in the user's home directory to store a history in. You can change this by setting HISTFILE in your .profile. I would recommend setting the following in /etc/profile:

USER=`/usr/bin/who am i | /bin/cut -d' ' -f 1`
MYTTY=`/usr/bin/tty`
BASETTY=`/bin/basename ${MYTTY}`
HISTFILE=${HOME}/.hist.${USER}.${BASETTY}
export readonly HISTFILE
HISTORY=100000
export readonly HISTORY

A lot of books espouse using $$, your PID. This is dumb. You get a separate shell history per login, but you create a boatload of files that never get reused. These self same books will tell you to do something stupid like create a cron job to delete any of these that are more than 3 days old. 3 days! Try 6 months! With the above, as you only have one (pseudo) terminal for each login session, each login session will get their own history. However, you will reuse the ttys, so you will reuse the history files. If HISTORY is large enough, however, you'll go back far enough. You can, however, trace back who had which tty when via the "last" command. There is no way to historically trace the PID. If you don't want to reuse the history files, add the date:

DATE=`/bin/date "+%Y%m%d.%H%M"`

I would put it between .hist and ${USER}. The ${USER} part may seem superflous, but if you have some account used by multiple users (like say "oracle"), then this allows you to see who did what. Because you take the username off of "who", you see their name before they su'ed (and of course you are going to set RLOGIN to "no" for a user like oracle so that users are forced to login as themselves and then su to the account, so that you have a paper trail to follow).

If we are talking about some derviative of C shell (csh), you have to put something in the user's .cshrc file (.login will not due) like:

set history = 100000
set savehist = 100000

Actually the first one is how many history command to show when they type "history", so that you might make smaller. No way to make it read-only. No way to set the file's name, it saves in $HOME/.history (like it or not). Furthermore, ksh writes to the history as it goes. csh writes to .history when it exits. Login into two windows, exit out of window A, exit out of window B - the history saved by window A gets overwritten and is lost; only the history of window B gets saved. For this reason, if history is important to you, csh is not your first choice.

Bourne shell doesn't do history at all.

The catch 22 is, if users can write to their history files, users can trash their own history files. Nothing you can do about that (other than say frequent backups).

Last edited by Garry_Garrett; 02-22-2006 at 08:25 PM.. Reason: pronoun mistake
 
PRUNEHISTORY(8) 					      System Manager's Manual						   PRUNEHISTORY(8)

NAME
prunehistory - remove file names from Usenet history file SYNOPSIS
prunehistory [ -f filename ] [ -p ] [ input ] DESCRIPTION
Prunehistory modifies the history(5) text file to ``remove'' a set of filenames from it. The filenames are removed by overwriting them with spaces, so that the size and position of any following entries does not change. Prunehistory reads the named input file, or standard input if no file is given. The input is taken as a set of lines. Blank lines and lines starting with a number sign (``#'') are ignored. All other lines are should consist of a Message-ID followed by zero or more file- names. The Messge-ID is used as the dbz(3) key to get an offset into the text file. If no filenames are mentioned on the input line, then all filenames in the text are ``removed.'' If any filenames are mentioned, they are converted into the history file notation. If they appear in the line for the specified Message-ID then they are removed. Since innd(8) only appends to the text file, prunehistory does not need to have any interaction with it. OPTIONS
-p Prunehistory will normally complain about lines that do not follow the correct format. If the ``-p'' flag is used, then the program will silently print any invalid lines on its standard output. (Blank lines and comment lines are also passed through.) This can be useful when prunehistory is used as a filter for other programs such as reap. -f The default name of the history file is /var/lib/news/history; to specify a different name, use the ``-f'' flag. EXAMPLES
It is a good idea to delete purged entries and rebuild the dbz database every so often by using a script like the following: ctlinnd throttle "Rebuilding history database" cd /var/lib/news awk 'NF > 2 { printf "%s %s %s", $1, $2, $3; for (i = 4; i <= NF; i++) printf " %s", $i; print " "; }' <history >history.n if makehistory -r -f history.n ; then mv history.n history mv history.n.pag history.pag mv history.n.dir history.dir else echo 'Problem rebuilding history; old file not replaced' fi ctlinnd go "Rebuilding history database" Note that this keeps no record of expired articles. HISTORY
Written by Rich $alz <rsalz@uunet.uu.net> for InterNetNews. This is revision 1.9, dated 1996/10/29. SEE ALSO
dbz(3), history(5), innd(8). PRUNEHISTORY(8)
All times are GMT -4. The time now is 11:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy