In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use logsave to save the command output, I hope you will learn something after reading this article, let's discuss it together!
Preface
What would you do if you wanted to save the output of the command to a file?
A common method is to use IO redirection.
Ls > / tmp/ls.txt 2 > & 1
If you need to save the command output to a file and output the content to the screen at the same time, we can use the tee command
Ls | tee / tmp/ls.txt
Today, however, I found that there is also a command for logsave, which can also save the command output to a file and output the content page to the screen.
The syntax of logsave is very simple:
Logsave [- asv] logfile cmd_prog [args...]
Option
-a: appends information to the specified log file.
Parameters.
Log files: specify log files that record running information
Instruction: an instruction that needs to be executed.
Logsave executes cmd_prog args... And save a copy of the command output to logfile. What is powerful about it is that even if the directory where logfile is located does not exist, logsave will save the output to memory and wait until the directory where logfile is established before writing to the log file.
This feature of logsave makes it suitable for use in system startup scripts, saving the output to memory until the / var/ directory is mounted and then writing it to / var/log/
For example, the following example
# Delete the directory where logfile is stored rm-rf / tmp/logdir# use logsave to save logfilelogsave / tmp/logdir/logfile bash-c "sleep 2 Date "# create logdirmkdir / tmp/logdirecho to check whether logfile is generated: ls-l / tmp/logdirecho wait 2s: sleep 2echo check whether logfile is generated again: ls-l / tmp/logdirecho check the contents of logfile: cat / tmp/logdir/logfile2018 May 14, Monday, 14, 2006, 16:31:44 CST check whether logfile is generated: total dosage 0 wait 2 seconds: check whether logfile is generated again: total consumption 4: RW Lujun9972 lujun9972 141 May 14 16:31 logfile View the contents of logfile: Log of bash-c sleep 2 Date Mon May 14 16:31:42 2018 May 14 Monday, 14 May 2018 16:31:44 CSTMon May 14 16:31:44 2018-
You can see from it:
Although logfile cannot be generated at first because logdir does not exist, after creating logdir, logsave finally successfully generates logfile and writes the execution result of the date command into it.
Logsave not only writes the output of the command to logfile, but also includes the command executed, the start time of the command execution and the end time of the command execution.
Cmd_prog in logsave can be a special-- which means that logsave gets the contents of the log to be logged from standard input, which allows logsave to be used like tee
Ls | wc-l | logsave / tmp/1.txt-> / dev/nullcat / tmp/1.txt after reading this article, I believe you have some understanding of "how to use logsave to save command output". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
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.