1753518 Members
5189 Online
108795 Solutions
New Discussion

Regarding shell /bin/csh

 
Narendra Uttekar
Regular Advisor

Regarding shell /bin/csh

Hi,
We use the following lines in /etc/profile as below to create the log file with command executed by that user. We are using login shell as /usr/bin/sh and it is working fine.


export LOGINNAME=`who am i | awk '{print $1}'`
export HISTFILE="/var/tmp/hist_`date +%y%m%d.%H%M%S`.${LOGINNAME}.$LOGNAME.$$"

 

We are having some users who are having login shell as /bin/csh. I tried the same by putting below lines in /etc/csh.login and .cshrc.  But it is not creating the log file in /var/tmp directory.


setenv LOGINNAME `who am i | awk '{print $1}'`
setenv HISTFILE "/var/tmp/hist_`date +%y%m%d.%H%M%S`.${LOGINNAME}.$LOGNAME.$$"

 

Please let me know what could be the problem for not creating the log file with command executed by that user in /var/tmp.

 

Thanks,
Narendra

 

 

P.S. this thread has been moved from HP-UX > System Administration to HP-UX > languages - HP Forums Moderator

1 REPLY 1
Matti_Kurkela
Honored Contributor

Re: Regarding shell /bin/csh

The csh shell is widely considered a flawed design.

 

The variable HISTFILE has no special meaning in csh - the shell treats it as just another user-defined environment variable with no impact to the working of the shell.

 

The name of the csh shell history file is hardcoded as '~/.history' - apparently that is not changeable at all.

 

There are two variables that control how many commands are kept in the history buffer of the csh shell and how many of those are saved to ~/.history. These are not environment variables, but shell variables: you should use "set" and "unset" instead of "setenv" and "unsetenv" with them. The names of the variables are $history and $savehist (note lower case).

 

You can set these to large values, but not to "infinite", so as soon as the number of commands the user has entered in a session becomes greater than the value of $history, some of the oldest commands will be forgotten. And since the .history file will be written at logout time and only $savehist last commands will be recorded, it will be easy for the user to avoid logging even without modifying any shell settings: just run $savehist innocent commands after any evil command, and the evil command is guaranteed to not appear in the .history file.

 

But there is an even easier way to avoid .history "logging": since the shell variables apparently cannot be made immutable in csh, the user can simply run "unset savehist" or "set savehist 0" and the current session won't be recorded.

 

Because of these differences, I would say that your trick with /usr/bin/sh is not applicable to csh at all.

MK