SWATCHDOG(1)
π NAME π
okay so bestie, welcome to swatchdog(1) β literally just a simple watcher. that's the whole name. simple watcher. iconic minimalism. π
β¨ 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 this whole thing designed to monitor system activity β like a little watchdog for your system, hence the name, iykyk. π
But bestie, hear me: it is not useful on its own. For Swatchdog to actually do anything, it requires a configuration file which contains the pattern(s) to look for and the action(s) to perform when each pattern is found. No config, no vibes. Periodt.
πΈ COMMAND LINE OPTIONS πΈ
okay this is the part where we go through every single flag because we don't skip. main character energy only. π
--awk-field-syntaxβ use this option only if you want to override regular expression backreferencing in favor ofawk(1)style field referencing. it's included for backward compatibility. (yes, "overide" is how the original spelled it, we're keeping the vibe.) π--config-file|-cfilename β tells swatchdog where to find its configuration file. the default is${HOME}/.swatchdogrc. π--daemonβ tells swatchdog to run in the background and disassociate itself from any terminal. it's giving "i'm leaving, don't follow me." π--extra-include-dir|-Ipath β tells swatchdog where to look for custom action modules.--extra-module|-Mmodule_name β tells swatchdog what custom action modules to load in.--help|-hβ prints usage information and exits. our fave. π«Ά--input-record-separator=regular_expression β tells swatchdog to use regular_expression to delineate the boundary of each input record. the default is a carriage return.--old-style-config|-Oβ tells swatchdog that your configuration file is written using the syntax that was abandoned back in the 1990's. retro. vintage. π--pid-filefile β writes the process ID to file. useful when running in daemon mode.--restart-time=[+]hh:mm[am|pm]or-r [+]hh:mm[am|pm]β restart at the specified time where hh is hours and mm is minutes. if the am/pm indicator is omitted, then a 24-hour clock is assumed. if the time is preceded by the+character, then the restart time will be set to the current time plus the specified time and the am/pm indicator will be ignored. β°--script-dir=/path/to/directoryβ this switch causes the temporary watcher script to be written to a file in the specified directory rather than the user's home directory.
β οΈ it is highly advised that you do NOT use directories that are writable by others such as /tmp. like, seriously. don't. π¨
--tail-argsarguments_for_tail_program β pass specific options to thetail(1)program.--tail-program-namefilename β runs an alternatetail(1)like program instead of the system default.--versionor-Vβ prints version information and exits.--use-cpan-file-tailβ use CPAN'sFile::Tailmodule to read the log file instead of thetail(1)command.
you may specify only one of the following options, bestie. pick one. one. singular. π
--tail-file=filename or-tfilename β examine lines of text as they are added to filename.--read-pipe=command or-pcommand β examine input piped in from the command.--examine=filename or-ffilename β use filename as the file to examine. Swatchdog will do a single pass through the named file.
the following options are purely for debugging purposes, but are documented here for completeness (we love a thorough queen):
--debug[=level]β spew out various levels of debugging for swatchdog developers. π--dump-script[=filename]β instead of running the watcher script after it is generated, it is written to filename or to STDOUT.
and here's a lil secret: if swatchdog is called with no options, it is 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
slay, defaults. β¨
π§ THE CONFIGURATION FILE π§
The configuration file is used by the swatchdog(8) program to determine what types of expression patterns to look for and what type of action(s) should be taken when a pattern is matched.
Each line should contain a keyword and a, sometimes optional, value for that keyword. The keyword and value are separated by a space or an equal (=) sign.
watchfor regex
ignore regex
echo [modes]β echo the matched line. the text mode may benormal,bold,underscore,blink,inverse,black,red,green,yellow,blue,magenta,cyan,white,black_h,red_h,green_h,yellow_h,blue_h,magenta_h,cyan_h, and/orwhite_h. the_hcolors specify a highlighting color. the other colors are assigned to the letters. some modes may not work on some terminals.Normalis the default. πbell [N]β echo the matched line, and send a bell N times (default =1). πexec commandβ execute command. the command may contain variables which are substituted with fields from the matched line. if the--awk-field-syntaxcommand-line option has been specified, then each$Nwill be replaced by the *N*th 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 have been escaped, regardless of the --awk-field-syntax option.
π an escaped$N,$0or$*may have unwanted effects since the value will be determined by the shell used to execute the command. just so you know.
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 into command. use thekeep_openoption to force the pipe to stay open until a different pipe action is run or until swatchdog exits.write [user:user:...]β usewrite(1)to send matched lines to user(s).throttle hours:minutes:seconds,[key=message|regex|<regexE]β this action has been depreciated. usethresholdinstead. for example,
throttle 15:00,key="foo"
would look like this
threshold track_by="foo",type=limit,count=1,seconds=900
π yeah, deprecated. don't be out here writing fresh throttle in 2023. we moved on, bestie.
threshold track_by=key, type=<limit|threshold|both, count=number, seconds=number>β thresholding can be done for the completewatchforblock 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 is 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 byseconds.bothβ 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 continue to try to match other pattern/action groups after it is done with the current pattern/action block. β‘οΈquitβ use this action to cause swatchdog to clean up and quit immediately. bye bestie. π
β 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
time windows?? for your notifications?? we love boundaries. π«Ά
π§ββοΈ FOR PERL HACKS ONLY π§ββοΈ
perlcode [depth] arbitrary_Perl_codeβ this permits you to easily insert random Perl code into yourswatchdogrcfile. the optional depth value 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 is 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. β³
like, it's literally a bouncer for your log messages. π
π 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 it will simply exit. Swatchdog will terminate gracefully when it receives a QUIT, TERM, or INT signal. β¨
so like, it handles its own exits. grown adult behavior. π
π AUTHOR π
E. Todd Atkins
Todd.Atkins@StanfordAlumni.ORG
we stan. π
π AVAILABILITY π
Swatchdog is a SourceForge project whose project page is at http://sourceforge.net/projects/swatchdog and homepage is at http://swatchdog.sourceforge.net
okay that's the whole page bestie, go forth and watch your logs π
β§ο½₯οΎ: * this lil tour was brought to you by perl v5.32.1, dated 2023-08-04 β mwah, take care, slay, and read your configs β§ο½₯οΎ:*
π¦ where this page comes from
- epel 9: swatchdog 3.2.4-2.el9 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms