1SWATCH(1)             User Contributed Perl Documentation            SWATCH(1)
2
3
4

NAME

6       swatch - simple watcher
7

SYNOPSIS

9       swatch [ --awk-field-syntax ] [ --config-file|-c file ] [ --daemon ] [
10       --extra-include-dir|-I path ] [ --extra-module|-M module_name ] [
11       --help|-h ] [ --input-record-separator regex ] [ --old-style-config|-O
12       ] [ --pid-file file ] [ --restart-time|-r time ] [ --script-dir path ]
13       [ --tail-args arguments_for_tail_program ] [ --tail-program-name
14       filename ] [ --version|-V ] [ --use-cpan-file-tail ] [ [ --examine|-f
15       file_to_examine ] | [ --read-pipe|-p program_to_pipe_from ] | [
16       --tail-file|-t file_to_tail ] ] [ --debug [ level ] ] [ --dump-script
17       filename ]
18

DESCRIPTION

20       Swatch is designed to monitor system activity.  In order for Swatch to
21       be useful, it requires a configuration file which contains pattern(s)
22       to look for and action(s) to perform when each pattern is found.
23

COMMAND LINE OPTIONS

25       --awk-field-syntax
26           Use this option only if you want to overide regular expression
27           backreferencing in favor of awk(1) style field referencing.
28           Included for backward compatability.
29
30       --config-file|-c filename
31           Tells swatch where to find its configuration file. The default is
32           ${HOME}/.swatchrc.
33
34       --daemon
35           This tells swatch to run in the background and disassociate itself
36           from any terminal.
37
38       --extra-include-dir|-I path
39           This tells swatch where to look for custom action modules.
40
41       --extra-module|-M module_name
42           This tells swatch what custom action modules to load in.
43
44       --help|-h
45           Prints usage information and exits.
46
47       --input-record-separator=regular_expression
48           Tells swatch to use regular_expression to delineate the boundary of
49           each input record. The default is a carriage return.
50
51       --old-style-config|-O
52           This tells swatch that your configuration file is written using the
53           syntax that was abandoned back in the 1990's.
54
55       --pid-file file
56           Writes the process ID to file. Useful when running in daemon mode.
57
58       --restart-time=[+]hh:mm[am|pm] or -r [+]hh:mm[am|pm]
59           Restart at the specified time where hh is hours and mm is minutes.
60           If the am/pm indicator is omitted, then a 24-hour clock is assumed.
61           If the time is preceded by the "+" character, then the restart time
62           will be set to the current time plus the specified time and the
63           am/pm indicator will be ignored.
64
65       --script-dir=/path/to/directory
66           This switch causes the temporary watcher script to be written to a
67           file in the specified directory rather than the user's home
68           directory. It is highly advised that you do NOT use directories
69           that are writable by others such as /tmp.
70
71       --tail-args arguments_for_tail_program
72           Pass specific options to the tail(1) program.
73
74       --tail-program-name filename
75           Runs an alternate tail(1) like program instead of the system
76           default.
77
78       --version or -V
79           Prints version information and exits.
80
81       --use-cpan-file-tail
82           Use CPAN's File::Tail module to read the log file instead of the
83           tail(1) command.
84
85       You may specify only one of the following options:
86
87       --tail-file=filename or -t filename
88           Examine lines of text as they are added to filename.
89
90       --read-pipe=command or -p command
91           Examine input piped in from the command.
92
93       --examine=filename or -f filename
94           Use filename as the file to examine.  Swatch will do a single pass
95           through the named file.
96
97       The following options are purely for debugging purposes, but are
98       documented here for completeness:
99
100       --debug[=level]
101           Spew out various levels of debugging for swatch developers.
102
103       --dump-script[=filename]
104           Instead of running the watcher script after it is generated, it is
105           written to filename or to STDOUT.
106
107       If swatch is called with no options, it is the same as typing the
108       command line
109
110               swatch --config-file=~/.swatchrc --tail-file=/var/log/syslog
111
112       or if /var/log/messages exists
113
114               swatch --config-file=~/.swatchrc --tail-file=/var/log/messages
115

THE CONFIGURATION FILE

117       The configuration file is used by the swatch(8) program to determine
118       what types of expression patterns to look for and what type of
119       action(s) should be taken when a pattern is matched.
120
121       Each line should contain a keyword and a, sometimes optional, value for
122       that keyword. The keyword and value are separated by a space or an
123       equal (=) sign.
124
125       watchfor regex
126
127       ignore regex
128
129       echo [modes]
130           Echo the matched line. The text mode may be normal, bold,
131           underscore, blink, inverse, black, red, green, yellow, blue,
132           magenta, cyan, white, black_h, red_h, green_h, yellow_h, blue_h,
133           magenta_h, cyan_h, and/or white_h. The _h colors specify a
134           highlighting color. The other colors are assigned to the letters.
135           Some modes may not work on some terminals. Normal is the default.
136
137       bell [N]
138           Echo the matched line, and send a bell N times (default = 1).
139
140       exec command
141           Execute command. The command may contain variables which are
142           substituted with fields from the matched line. A $N will be
143           replaced by the Nth field in the line. A $0 or $* will be replaced
144           by the entire line.
145
146       mail [addresses=address:address:...][,subject=your_text_here]
147           Send mail to address(es) containing the matched lines as they
148           appear (default address is the user who is running the program).
149
150       pipe command[,keep_open]
151           Pipe matched lines into command. Use the keep_open option to force
152           the pipe to stay open until a different pipe action is run or until
153           swatch exits.
154
155       write [user:user:...]
156           Use write(1) to send matched lines to user(s).
157
158       throttle hours:minutes:seconds,[key=message|regex|<regexE]>
159           This action has been depreciated. Use threshold instead For
160           example,
161
162               throttle 15:00,key="foo"
163
164           would look like this
165
166               threshold track_by="foo",type=limit,count=1,seconds=900
167
168       threshold track_by=key, type=<limit|threshold|both, count=number,
169       seconds=number>
170           Thresholding can be done for the complete watchfor block and/or for
171           individual actions. Add "threshold=on" as an option along with the
172           other threshold options when thresholding an individual action.
173
174           track_by
175               The value of this should be something that is unique to the
176               watchfor regular expression. Tip: enclose unique parts of the
177               regular expression in parentheses, then use the sub matches as
178               part of the value (e.g. track_by="$2:$4").
179
180           type
181               There are three types of thresholding. They are as follows:
182
183               limit
184                   Perform action(s) for the first "count" matches during the
185                   time interval specified by "seconds", then ignore events
186                   for the rest of the time interval (kind of like throttle)
187
188               threshold
189                   Perform action(s) on each match for up to count matches
190                   during the time interval specified by seconds
191
192               both
193                   Perform actions(s) once per time interval after "count"
194                   matches occur, then ignore additional matches during the
195                   time interval specified by "seconds"
196
197       continue
198           Use this action to cause swatch to continue to try to match other
199           pattern/action groups after it is done with the current
200           pattern/action block.
201
202       quit
203           Use this action to cause swatch to clean up and quit immediately.
204

SPECIAL OPTION

206       The following may be used as an option for any of the above actions
207       except for throttle and threshold.
208
209       when=day_of_week:hour_of_day
210           Use this option to specify windows of time and days when the action
211           can be performed.  For example:
212
213               mail=sysad-pager@somehost.somedomain,when=1-6:8-17
214

FOR PERL HACKS ONLY

216       perlcode [depth] arbitrary_Perl_code
217           This permits you to easily insert random Perl code into your
218           swatchrc file.  The optional depth value tells swatch how deep into
219           the code to put the perl code. (0=outside the main loop, 1=inside
220           the main loop (default), 2=just inside the conditional used by the
221           current watchfor statement, and 3=inside the throttle block).
222
223           Its intended use is to permit variable substitution. For example:
224
225               perlcode $syslog="^\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}.*";
226
227               watchfor /$syslog hostname pppd/>
228
229           but any valid Perl is permitted.  Remember the semicolon, and make
230           judicious use of the --dump-script option if you run into trouble.
231

CONFIGURATION EXAMPLE

233       In this example, a line which contains the string "file system full"
234       will be echoed and the screen bell will sound.  Also, threshold will
235       use what is matched within the parentheses as its key rather than
236       trying to use the log message with its time stamp cut out. Multiple
237       instances of the message will not be echoed if they appear within a
238       minute of the first one. Instead the following message will be acted
239       upon after the time interval has expired.
240

SEE ALSO

242       signal(3), perl(1), perlre(1)
243

NOTES

245       Upon receiving an ALRM or HUP signal swatch will re-read the
246       configuration file and restart, except when used with the --daemon
247       command line option where it will simply exit.  Swatch will terminate
248       gracefully when it receives a QUIT, TERM, or INT signal.
249

AUTHOR

251           E. Todd Atkins
252           Todd.Atkins@StanfordAlumni.ORG
253

AVAILABILITY

255       Swatch is a SourceForge project whose project page is at
256       http://sourceforge.net/projects/swatch and homepage is at
257       http://swatch.sourceforge.net
258

POD ERRORS

260       Hey! The above document had some coding errors, which are explained
261       below:
262
263       Around line 1350:
264           You forgot a '=back' before '=head1'
265
266
267
268perl v5.12.1                      2008-07-01                         SWATCH(1)
Impressum