Operating System - HP-UX
1753878 Members
7219 Online
108809 Solutions
New Discussion юеВ

Re: enabling history file for root

 
satheeshnp
Advisor

enabling history file for root

I am using hp 11.23.Even though i have .Sh_history file,None of the previous command are not saved.

I enabled history variable.But i can't see previous command.Help to enable history.
6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: enabling history file for root

root is special in the POSIX shell. As documented, you must export HISTFILE before history works.
satheeshnp
Advisor

Re: enabling history file for root

export HISTFILE=/.sh_history
export HISTSIZE=100


i have exported. How i can get back the previous command.Wat key combination should use.
Dennis Handly
Acclaimed Contributor

Re: enabling history file for root

>How I can get back the previous command? What key combination should use?

You also have to select vi or emacs editing with "set -o vi".
For vi, you use Esc k.
SoorajCleris
Honored Contributor

Re: enabling history file for root

Hi

you can use vi keys to get and edit the commands

Esc

k - go up ==> previous command
j= go down

you may use #history to get last 10 command list

#history -20 will show you last 20 commands

Regards,
Sooraj
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity" - Dennis Ritchie
satheeshnp
Advisor

Re: enabling history file for root

Esc K is not working. More over .sh_history file is not updated. It always shows zero bytes.

Why I dont know.
I have exported both the variable.This is for root only.For all other users its working.

Bill Hassell
Honored Contributor

Re: enabling history file for root

> export HISTFILE=/.sh_history
> export HISTSIZE=100

First, this command should be stored on /etc/profile so all users have the benefit of a working history. However, never use /.sh_history. Instead, you specify the HOME directory so it works for all users:

export HISTFILE=$HOME/.sh_history

Second, the HISTSIZE should be much, much larger, especially for root. Set it to 5000 or 10000 so you can see what was done several weeks or months ago.

As a side note, / is the worst possible directory for root's $HOME. This is the most important directory in Unix and if you make a mistake like cd'ing to a misspelled directory, miss the error message and then issue rm -r or chmod -R or chown -R, you will destroy the ENTIRE system.

If root's HOME is /, create a directory called /root, chmod 755 /root and then move all the root files to /root. Now change root's HOME in /etc/passwd -- use vipw as a good habit for editing the passwd file.

> set -o vi

Include this in /etc/profile so all users have a consistent setting for command line recall and editing. Individual users can change this in their local .profile files.

> Esc K is not working. More over .sh_history file is not updated. It always shows zero bytes.

After you move root's $HOME and add the above 3 lines to /etc/profile, you need to logout and log back in, at which point the shell history will work. NOTE: this assumes that you have not broken the root shell by changing it to something other than /sbin/sh. If you have, IMMEDIATELY change it back to /sbin/sh using:

chsh root /sbin/sh

If you use some other shell (/bin/ksh, /usr/local/bin/bash, etc), root will be unable to do anything with the system in single user mode, not a good situation.


Bill Hassell, sysadmin