In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what is the use of the script command in Linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
The Linux common command script is used to record the output information of all the actions and commands of the user in a terminal session.
Script records all operations of the terminal session
In short, recording all the information that takes place in a terminal session is like a terminal video recorder. For example, when a user enters a command, the typing and deletion of characters are also recorded. All the operations of the user in the terminal, the echo of the terminal and other information will be stored in the log file in raw format, which is called the terminal data file. The time information of the command is stored as a log file in another structure, called the time log file. Use the command exit or the shortcut key Ctrl + D to stop recording.
Syntax script (option) (parameter) option-a,-append # operation information on the terminal session, write to the file in an appended manner (keeping the contents of the original file)-c,-- command command # only runs the command command and does not open the interactive terminal. Equivalent to opening script, executing command, and then exiting script # command can be any command that can be executed in a terminal session-e,-return # returns the exit status code of the child process-f,-flush # each time the content of the terminal changes Write log files immediately-force # allows default output terminal data files to be symbolic links-o,-output-limit size # limits the size of terminal data files and time log files When the file size reaches this limit, the unit of child process # size can be set to: KiB (= 1024), KB (= 1000), MiB (1024 / 1024), MB (= 1000 / 1000). Similarly, GiB TiB PiB EiB ZiB YiB GB TB PB EB ZB YB-Q,-quiet # quiet mode is also supported. The start and exit script commands do not display any prompts-t [file],-- timing [= file] # output time log information to standard error (stderr) or file-V,-- version # displays version information and exits-h,-- help # displays help text and exits parameter terminal data file: sets the file name that stores terminal data information
Instance script # opens the record. By default, a file named typescript is created in the current directory to save the terminal data file script command.log # Open record, and a file named command.log is created in the current directory to save the terminal data file script-T2 > time.file command.log # Open record Create a file named command.log in the current directory to save the terminal data file # create a file named time.file in the current directory to save the time log file and record the terminal information in append mode
Zfb@localhost:~$ script-T2 > time.file-a-f command.log Script started, file is command.log zfb@localhost:~$ echo "hello, world" hello, world zfb@localhost:~$ echo $(date "+% Y-%m-%d% H:%M:%S") 2020-12-23 20:48:46 zfb@localhost:~$ echo "Bye" Bye zfb@localhost:~$ ls-al total 20 drwxr-xr-x 2 zfb zfb 4096 Dec 23 20:48. Drwxr-xr-x 37 zfb zfb 4096 Dec 23 20:49.. -rw-r--r-- 1 zfb zfb 0 Dec 23 19:03 a.txt-rw-r--r-- 1 zfb zfb 12 Dec 23 19:04 b.txt-rw-r--r-- 1 zfb zfb 2744 Dec 23 20:49 command.log-rw-r--r-- 1 zfb zfb 790 Dec 23 20:49 time.file zfb@localhost:~$ exit Script done, file is command.log zfb@localhost:~$ then the user can view the terminal data file as follows
Zfb@localhost:~$ cat command.log Script started on 2020-12-23 20 TTY= 48V 250.08 TTY= [TERM= "xterm-256color" TTY= "/ dev/pts/0" COLUMNS= "75" LINES= "30"] zfb@localhost:~$ echo "hello, world" hello World zfb@localhost:~$ echo $(date "+% Y-%m-%d% H:%M:%S") 2020-12-23 20:48:46 zfb@localhost:~$ echo "Bye" Bye zfb@localhost:~$ ls-al total 20 drwxr-xr-x 2 zfb zfb 4096 Dec 23 20:48 Drwxr-xr-x 37 zfb zfb 4096 Dec 23 20:49.. -rw-r--r-- 1 zfb zfb 0 Dec 23 19:03 a.txt-rw-r--r-- 1 zfb zfb 12 Dec 23 19:04 b.txt-rw-r--r-- 1 zfb zfb 2744 Dec 23 20:49 command.log-rw-r--r-- 1 zfb zfb 790 Dec 23 20:49 time.file zfb@localhost:~$ exit Script done on 2020-12-23 20 Dec 49 COMMAND_EXIT_CODE= "0"] zfb@localhost:~$ of which Only the command cat command.log is entered by the user, and the rest are automatically rendered. By looking at the time output above, at 20:48:46, it can be proved that this is a reproduced record rather than a re-execution of the command. In other words, time.file and command.log files can be moved to any machine, command input and terminal echo can be reproduced.
Record server user session operations
Edit the file / etc/profile as root, appending the following to the end of the file
If [$UID- ge 0] then exec / usr/bin/script-T2 > / var/log/script-records/$USER-$UID- `date +% Y% m% d`.time-a-f-Q / var/log/script-records/$USER-$UID- `date +% Y% m% d`.log fi and then create a folder as root to store all operation information of each user on the server on the terminal
Sudo mkdir-p / var/log/script-records/ sudo chmod 733 / var/log/script-records/ finally, execute the command source / etc/profile. All operations performed by any user (UID ≥ 0) at the terminal are quietly recorded and stored in days.
This is the end of this article on "what is the use of script commands in Linux?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.