How to get users history as mail..

Hi all,

Thanks in Advance,

i want to view my users commands, what commands they are using in their terminal like that, how to automate this history process daily.

What's your system?

you mean Distro?

Centos 6

normally we can view commands using history command, but how can we automate this process as daily, is it possible to get the command details in daily basis?

There's more OSes than Linux. Look at the forum list and you'll see a variety of UNIX and UNIX-like systems.

So your system is Linux, and your distro is Centos.

You could put it into a cron job. crontab -e and put this into your cron table:

# 5 minutes after midnight, every day
5 0 * * * /path/to/script.sh

which will run your history script every day. Beware that cron's environment is minimal, you might need to set a better PATH in your script.

:frowning: :frowning: :frowning: hmm Iam asking how to get the commands , History is the only way?? i know Crontab and all.

history, the command, is a shell builtin, not an external thing. Some shells don't have it at all. How to get at the data from outside depends on what shell they use.

If you use the bash shell, the history data will be in ~/.bash_history. You can just read that.

~/.bash_history gets updated by bash only when the user quits their shell.

1 Like

Be advised that the location of the history file for both Kshell and bash is controlled with the HISTFILE environment variable. If a user sets this, (I do, and most people I work with do), you might not find anything or everything that you expect. Further, history won't have any details about commands that were executed from scripts started from the command line, nor will it have any information about what users are executing from at or cron.

Depending on what your goal is, you might consider using system accounting to track how your systems are being used. See the man pages for accton which turns accounting on/off, sa which summarises accounting information and lastcomm which lists the accounting information by user and/or by command and shows execution time and elapsed time (information you'll not get by looking at the history).

System accounting will show all commands run by all users, not just what was run from the command line.

Link to lastcomm manpage which should reference other related pages:
Man Page for lastcomm (All Section 1) - The UNIX and Linux Forums