1833859 Members
2237 Online
110063 Solutions
New Discussion

Sudo

 
johnreid
Contributor

Sudo

Hi all,

I am login with my user id and password and then sudo su – mywork area , is there any chance to have a history of commands executed my me , after sudo or before sudo
5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: Sudo

Shalom,

You can set it up.

export HISTFILE=~/.sh_history
export HISTSIZE=5000

This makes a file and limits the size. Not available with c shell.

You can if you have permissions build this feature into your .profile.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
spex
Honored Contributor

Re: Sudo

Hi John,

sh-posix and ksh store the command history to ~/.sh_history by default. Both of these shells have a default HISTSIZE of 128, but this can be changed by exporting the new value to the environment.

If you'd like the command history for user1 and user2 to be recorded to the same file, add, for instance, 'HISTFILE=/usr/local/share/hist; export HISTFILE' to ~/.profile for each user.

PCS
Emil Velez
Honored Contributor

Re: Sudo

agree with previous posters about .sh_history plus

Remember sudo also logs the commands in the syslog.log file..
Wouter Jagers
Honored Contributor

Re: Sudo

Also check out the 'script' command.

If you put 'script /tmp/roothist.txt' in root's profile, all commands issued by root will be recorded in this file.

'script -a /tmp/roothist.txt' will also append the output of these commands.

Do keep an eye on these files, though.. they are NOT automatically cleaned up and could fill up lots of diskspace after a while.

Cheers
an engineer's aim in a discussion is not to persuade, but to clarify.
Wouter Jagers
Honored Contributor

Re: Sudo

Naturally, you can try out the script command manually first, it will start recording as soon as you issue it. Then you can decide whether it's useful for you.

Cheers
an engineer's aim in a discussion is not to persuade, but to clarify.