Want to know what the user has done after logging into the system, how to do?
Don't worry, Linux has a script tool that specifically records all input and output results in a terminal session and stores it in a specified file.
Let's see how to record it first!
1. Create Log storage Directory
# mkdir/opt/operation_log# chmod 777-r/opt/operation_log
2. Set up automatic recording after user login
# vi/etc/profile #末尾追加一下内容if [$UID-ge 500]; Then exec script-t 2>/opt/operation_log/$USER-$UID-' date +%f-%t '. Date-a-q-f/opt/operation_log/$USER-$UID-' date + %f-%t '. logfi# source/etc/profile #刷新生效
Parameter description:
-T: Record operation timing,2> The timing of the output to the specified file, using this time file for playback
-A: The output is appended to the file
-Q: Silent start
-F: Refresh output after each write
3. View the generated files
# ll/opt/operation_log/total 8-rw-rw-r--1 Test test 124 Jul 3 07:17 test-1001-2015-07-03-07:17:36.date-rw-rw-r--1 Test Test 167 Jul 3 07:17 Test-1001-2015-07-03-07:17:36.log
As you can see, the log format we define is generated separately.
When using log logs for a long time, with more or cat view is more laborious, then there is a corresponding tool called Scriptrelay, by combining script output of the timing file, can be automatically played.
4. Operation Record Replay
# Scriptreplay Test-1001-2015-07-03-07:17:36.date Test-1001-2015-07-03-07:17:36.log
Isn't it much easier!
If you simply record this operation command, you can run it directly:
# Script Test
Will switch to script, wait until you finish the command, enter exit to exit, and then view the test file.
This article is from the "Li Zhenliang Technology Blog" blog, make sure to keep this source http://lizhenliang.blog.51cto.com/7876557/1670563
Operation Record of monitoring user under Linux