SWATCHDOG(1p)
πΈ SWATCHDOG(1p) πΈ
okay bestie, welcome to the swatchdog page β that's section 1p, straight out of the User Contributed Perl Documentation. she's a simple watcher and she's iconic, let's get into it π
β¨ NAME β¨
swatchdog β simple watcher π
π¦ SYNOPSIS π¦
swatchdog [ --awk-field-syntax ] [ --config-file|-c file ] [ --daemon ]
[ --extra-include-dir|-I path ] [ --extra-module|-M module_name ] [
--help|-h ] [ --input-record-separator regex ] [ --old-style-config|-O ]
[ --pid-file file ] [ --restart-time|-r time ] [ --script-dir path ] [
--tail-args arguments_for_tail_program ] [ --tail-program-name filename
] [ --version|-V ] [ --use-cpan-file-tail ] [ [ --examine|-f
file_to_examine ] | [ --read-pipe|-p program_to_pipe_from ] | [
--tail-file|-t file_to_tail ] ] [ --debug [ level ] ] [ --dump-script
filename ]
π DESCRIPTION π
So, Swatchdog is built to monitor system activity. lowkey her whole thing π«Ά
But here's the tea: for Swatchdog to actually be useful, she needs a configuration file. That file is where you put the pattern(s) to look for, and the action(s) to do whenever one of those patterns gets matched. No config, no vibes. periodt.
π COMMAND LINE OPTIONS π
--awk-field-syntaxβ only use this one if you wanna override regular expression backreferencing and go with awk(1) style field referencing instead. it's here for backward compatibility, bestie, she's a legacy queen π--config-file|-c filenameβ tells swatchdog where her configuration file lives. the default is${HOME}/.swatchdogrc.--daemonβ tells swatchdog to run in the background and disassociate herself from any terminal. main character going off-grid β¨--extra-include-dir|-I pathβ tells swatchdog where to look for custom action modules.--extra-module|-M module_nameβ tells swatchdog which custom action modules to load in.--help|-hβ prints usage info and dips out.--input-record-separator=regular_expressionβ tells swatchdog to useregular_expressionto mark the boundary of each input record. the default is a carriage return.--old-style-config|-Oβ tells swatchdog your config file is written in the syntax that got abandoned back in the 1990's. vintage fr fr π°οΈ--pid-file fileβ writes the process ID tofile. super useful when you're running in daemon mode.--restart-time=[+]hh:mm[am|pm]or-r [+]hh:mm[am|pm]β restart at the specified time, wherehhis hours andmmis minutes. if you leave out theam/pmindicator, a 24-hour clock is assumed. and if the time is preceded by the+character, then the restart time gets set to the current time plus the specified time, and theam/pmindicator gets ignored entirely.--script-dir=/path/to/directoryβ this switch makes the temporary watcher script get written to a file in the specified directory instead of the user's home directory.
β οΈ it is highly advised that you do NOT use directories that are writable by others such as /tmp. seriously bestie, don't do it π
--tail-args arguments_for_tail_programβ pass specific options through to the tail(1) program.--tail-program-name filenameβ runs an alternate tail(1)-like program instead of the system default.--versionor-Vβ prints version info and exits.--use-cpan-file-tailβ use CPAN'sFile::Tailmodule to read the log file instead of the tail(1) command.
π you may specify only ONE of the following options π
pick your fighter, bestie, you only get one:
--tail-file=filenameor-t filenameβ examine lines of text as they get added tofilename.--read-pipe=commandor-p commandβ examine input piped in from the command.--examine=filenameor-f filenameβ usefilenameas the file to examine. Swatchdog will do a single pass through the named file.
π the debug girlies (documented for completeness)
The following options are purely for debugging purposes, but they're documented here for completeness:
--debug[=level]β spew out various levels of debugging for swatchdog developers.--dump-script[=filename]β instead of running the watcher script after it's generated, it gets written tofilenameor toSTDOUT.
π¦ the no-options vibe π¦
If swatchdog is called with no options at all, it's the same as typing the command line:
swatchdog --config-file=~/.swatchdogrc --tail-file=/var/log/syslog
or, if /var/log/messages exists:
swatchdog --config-file=~/.swatchdogrc --tail-file=/var/log/messages
π THE CONFIGURATION FILE π
The configuration file is what the swatchdog(8) program uses to figure out what types of expression patterns to look for, and what type of action(s) to take when a pattern is matched.
Every line should have a keyword and a β sometimes optional β value for that keyword. The keyword and value are separated by a space or an equal (=) sign.
watchfor regexignore regexecho [modes]β echo the matched line. Thetextmode may benormal,clear,reset,boldunderline,underscore,blink,reverse,concealed,black,redgreen,yellow,blue,magenta,on_black,on_red,on_greenon_yellow,on_blue,on_magenta,on_cyan,on_white. The<on_>colors specify a highlighting color. Some modes may not work on some terminals.Normalis the default. For modes changes and additions, check the perl moduleTerm::ANSIColorman page.bell [N]β echo the matched line, and send a bellNtimes (default =1). πexec commandβ executecommand. The command may contain variables which get substituted with fields from the matched line. If the--awk-field-syntaxcommand-line option has been specified, then each$Nwill be replaced by theNth field in the line. If the option has not been specified, then each$Nwill refer to a backreference in the regular expression used to match the line.
A $0 or $* will always be replaced by the entire line, unless they've been escaped, regardless of the --awk-field-syntax option.
An escaped $N, $0 or $* may have unwanted effects since the value will be determined by the shell used to execute the command.
mail [addresses=address:address:...][,subject=your_text_here]β send mail to address(es) containing the matched lines as they appear (default address is the user who is running the program).pipe command[,keep_open]β pipe matched lines intocommand. Use thekeep_openoption to force the pipe to stay open until a different pipe action is run or until swatchdog exits.write [user:user:...]β use write(1) to send matched lines to user(s).throttle hours:minutes:seconds,[key=message|regex|<regexE]>
β οΈ This action has been depreciated. Use threshold instead.
For example,
throttle 15:00,key="foo"
would look like this:
threshold track_by="foo",type=limit,count=1,seconds=900
threshold track_by=key, type=<limit|threshold|both, count=number, seconds=number>
Thresholding can be done for the complete watchfor block and/or for individual actions. Add "threshold=on" as an option along with the other threshold options when thresholding an individual action.
track_byβ the value of this should be something that's unique to thewatchforregular expression. Tip: enclose unique parts of the regular expression in parentheses, then use the sub matches as part of the value (e.g.track_by="$2:$4").typeβ there are three types of thresholding. They are as follows:limitβ perform action(s) for the first"count"matches during the time interval specified by"seconds", then ignore events for the rest of the time interval (kind of like throttle)thresholdβ perform action(s) on each match for up tocountmatches during the time interval specified bysecondsbothβ perform actions(s) once per time interval after"count"matches occur, then ignore additional matches during the time interval specified by"seconds"
continueβ use this action to cause swatchdog to keep trying to match other pattern/action groups after she's done with the current pattern/action block. she's not done yet πquitβ use this action to cause swatchdog to clean up and quit immediately.
β SPECIAL OPTION β
The following may be used as an option for any of the above actions except for throttle and threshold.
when=day_of_week:hour_of_dayβ use this option to specify windows of time and days when the action can be performed. For example:
mail=sysad-pager@somehost.somedomain,when=1-6:8-17
π§ FOR PERL HACKS ONLY π§
perlcode [depth] arbitrary_Perl_codeβ this permits you to easily insert random Perl code into yourswatchdogrcfile. The optionaldepthvalue tells swatchdog how deep into the code to put the perl code. (0=outside the main loop,1=inside the main loop (default),2=just inside the conditional used by the currentwatchforstatement, and3=inside the throttle block).
Its intended use is to permit variable substitution. For example:
perlcode $syslog="^\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2}.*";
watchfor /$syslog hostname pppd/>
but any valid Perl is permitted. Remember the semicolon, and make judicious use of the --dump-script option if you run into trouble. π«Ά
π CONFIGURATION EXAMPLE π
perlcode my $fsf_regex = '\d{2}:\d{2}:\d{2}\s+(.* file system full)';
watchfor /$fsf_regex/
threshold track_by=$1,type=limit,count=1,seconds=60
echo
bell
In this example, a line which contains the string "file system full" will be echoed and the screen bell will sound. Also, threshold will use what's matched within the parentheses as its key rather than trying to use the log message with its time stamp cut out. Multiple instances of the message will not be echoed if they appear within a minute of the first one. Instead, the following message will be acted upon after the time interval has expired. no cap π₯
π SEE ALSO π
πΈ NOTES πΈ
Upon receiving an ALRM or HUP signal, swatchdog will re-read the configuration file and restart β except when used with the --daemon command line option, where she'll simply exit. Swatchdog will terminate gracefully when she receives a QUIT, TERM, or INT signal. she's dramatic but she's polite β¨
π AUTHOR π
E. Todd Atkins
Todd.Atkins@StanfordAlumni.ORG
π¦ AVAILABILITY π¦
Swatchdog is a SourceForge project whose project page is at http://sourceforge.net/projects/swatchdog and homepage is at http://swatchdog.sourceforge.net
and that's the whole page bestie, you ate π this was served up by perl v5.36.0, dated 2023-01-20, and it's the SWATCHDOG(1p) page β go forth and watch things, queen ππ
π¦ where this page comes from
- debian bookworm: swatch 3.2.4-5 Β· GPL-2.0-or-later
- debian trixie: swatch 3.2.4-5 Β· GPL-2.0-or-later
- ubuntu noble: swatch 3.2.4-5 Β· GPL-2.0-or-later
- ubuntu questing: swatch 3.2.4-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms