Debian Codegraph @

ex41.sh

raw symbols SCIP
1 #!/bin/bash
2
3 # Generates a log file in current directory
4 # from the tail end of /var/log/messages.
5
6 # Note: /var/log/messages must be world readable
7 # if this script invoked by an ordinary user.
8 # #root chmod 644 /var/log/messages
9
10 LINES=5
11
12 ( date; uname -a ) >>logfile
13 # Time and machine name
14 echo ---------------------------------------------------------- >>logfile
15 tail -n $LINES /var/log/messages | xargs | fmt -s >>logfile
16 echo >>logfile
17 echo >>logfile
18
19 exit 0
20
21 # Note:
22 # ----
23 # As Frank Wang points out,
24 #+ unmatched quotes (either single or double quotes) in the source file
25 #+ may give xargs indigestion.
26 #
27 # He suggests the following substitution for line 15:
28 # tail -n $LINES /var/log/messages | tr -d "\"'" | xargs | fmt -s >>logfile
29
30
31
32 # Exercise:
33 # --------
34 # Modify this script to track changes in /var/log/messages at intervals
35 #+ of 20 minutes.
36 # Hint: Use the "watch" command.