2001-07-10 14:25:50 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Generates a log file in current directory
|
|
|
|
# from the tail end of /var/log/messages.
|
|
|
|
|
2001-09-04 13:27:31 +00:00
|
|
|
# Note: /var/log/messages must be world readable
|
|
|
|
# if this script invoked by an ordinary user.
|
|
|
|
# #root chmod 644 /var/log/messages
|
|
|
|
|
|
|
|
LINES=5
|
2001-07-10 14:25:50 +00:00
|
|
|
|
|
|
|
( date; uname -a ) >>logfile
|
|
|
|
# Time and machine name
|
2006-12-20 21:11:55 +00:00
|
|
|
echo ---------------------------------------------------------- >>logfile
|
2006-10-11 16:39:10 +00:00
|
|
|
tail -n $LINES /var/log/messages | xargs | fmt -s >>logfile
|
2001-07-10 14:25:50 +00:00
|
|
|
echo >>logfile
|
|
|
|
echo >>logfile
|
|
|
|
|
|
|
|
exit 0
|
2003-05-12 14:45:05 +00:00
|
|
|
|
2004-10-03 17:40:48 +00:00
|
|
|
# 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:
|
2006-12-20 21:11:55 +00:00
|
|
|
# tail -n $LINES /var/log/messages | tr -d "\"'" | xargs | fmt -s >>logfile
|
2004-10-03 17:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Exercise:
|
|
|
|
# --------
|
2003-05-12 14:45:05 +00:00
|
|
|
# Modify this script to track changes in /var/log/messages at intervals
|
|
|
|
#+ of 20 minutes.
|
|
|
|
# Hint: Use the "watch" command.
|