View operation history in Linux

Source: Internet
Author: User
Tags syslog


The last command can be used to view User Login records.
The history command can view the command execution history. Common log files www.2cto.com are as follows: access-log record HTTP/web transmission acct/pacct record USER command aculog record MODEM activity btmp record failure record lastlog record recent successful login events and last unsuccessful log on to messages to record information from syslog (some links to the syslog file) sudolog records the use of sudo commands sulog records the use of syslogs using the su command to record information from syslogs (usually linked to the messages file) utmp records the number of currently logged-on users. Each user wtmp records the number of permanent records for each login Entry and Exit Time. xferlog records the FTP session ~ /. Bash_history contains no time records. You can use the following script to record the time.

You can add the following code to/etc/profile: PS1 = "'whoam' @ 'hostname ': "'[$ PWD] 'History www.2cto.com USER_IP = 'Who-u am I 2>/dev/null | awk' {print $ NF} '| sed-e's /[ ()] // g'' # print $ NF obtain the field of the last domain if ["$ USER_IP" = ""] then USER_IP = 'hostname' fi if [! -D/tmp/dbasky] then mkdir/tmp/dbasky chmod 777/tmp/dbasky fi if [! -D/tmp/dbasky/$ {LOGNAME}] then mkdir/tmp/dbasky/$ {LOGNAME} chmod 300/tmp/dbasky/$ {LOGNAME} fi export HISTSIZE = 4096 DT = 'date "% Y % m % d _ % H % M % S" 'export HISTFILE = "/tmp/dbasky/$ {LOGNAME}/$ {USER_IP} dbasky. $ DT "chmod 600/tmp/dbasky/$ {LOGNAME}/* dbasky * 2>/dev/null
In fact, the above Code cannot tell you that it is very convenient to create a dbasky directory in/tmp of the system and record all users and IP addresses that have logged on to the system in the directory? We can also use this method to monitor system security. Www.2cto.com, you can see that there is no time to display the history command, and you do not know when the command is executed. At this time, you can edit the/etc/bashrc file and add the following three lines: HISTFILESIZE = 2000 HISTSIZE = 2000 HISTTIMEFORMAT = "% Y % m % d-% H % M % S:" export HISTTIMEFORMAT
Save and exit. Close the current shell and log on again ~ /. In the bash_History file, the command execution time is recorded by the author huaius.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.