ex41.sh

来自「Shall高级编程」· Shell 代码 · 共 37 行

SH
37
字号
#!/bin/bash# Generates a log file in current directory# from the tail end of /var/log/messages.# Note: /var/log/messages must be world readable# if this script invoked by an ordinary user.#         #root chmod 644 /var/log/messagesLINES=5( date; uname -a ) >>logfile# Time and machine nameecho ---------------------------------------------------------- >>logfiletail -n $LINES /var/log/messages | xargs | fmt -s >>logfileecho >>logfileecho >>logfileexit 0#  Note:#  ----#  As Frank Wang points out,#+ unmatched quotes (either single or double quotes) in the source file#+ may give xargs indigestion.##  He suggests the following substitution for line 15:#  tail -n $LINES /var/log/messages | tr -d "\"'" | xargs | fmt -s >>logfile#  Exercise:#  --------#  Modify this script to track changes in /var/log/messages at intervals#+ of 20 minutes.#  Hint: Use the "watch" command. 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?