Linux records commands executed by users

Source: Internet
Author: User
Add [plain] exportHISTSIZE50000exportHISTORY_FILE/var/log/CommandHistory in the/etc/profile file for commands executed by linux record system users. logexportPROMPT_COMMAND & amp; #39; {thisHistID 'histor linux records the commands executed by the system users are added to the/etc/profile file: [plain] export HISTSIZE = 50000 export HISTORY_FILE =/var/log/CommandHistory. log export PROMPT_COMMAND = '{thisHistID = 'History 1 | awk "{print \ $1 }"'; lastCommand = 'History 1 | awk "{\\$ 1 = \" \ "; print}" '; user = 'id-un '; WhoStr = ('who-u am I '); realUser =$ {whoStr [0]}; logMonth =$ {whoStr [2]}; logDay =$ {whoStr [3]}; pid =$ {whoStr [5]}; ip =$ {whoStr [6]}; if [$ {thisHistID} x! =$ {LastHistID} x]; then echo-E 'date "+ % Y/% m/% d % H: % M: % S "'$ user \ ($ realUser \) @ $ ip [Pid: $ pid] [LoginTime: $ logMonth $ logDay] ExecuteCommand: $ lastCommand; fi; }>> $ HISTORY_FILE: # chmod 777/var/log/CommandHistory. regular log cleanup script: [plain] #! /Bin/bash dt = 'date + "% Y % m % d % H % M" 'Find/var/log/-name "CommandHistory *. log "-mtime + 15-exec rm-f {}\; cat/var/log/CommandHistory. log>/var/log/CommandHistory $ dt. log>/var/log/CommandHistory. log crontab is set to run once a day, clear command records 15 days ago, back up command records from the previous day

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.