fetchlog(1)
β¨ NAME β¨
fetchlog β fetch and convert new messages of a logfile π
okay bestie, quick vibe check: this is the fetchlog(1) manual page, and by the end of it you're gonna know exactly how to pull just the new bits out of a logfile and make them look cute (or at least shell-safe). no cap. π¦
πΈ SYNOPSIS πΈ
fetchlog -f first:last:len:conv logfile bookmarkfile [ pattern .. ]
fetchlog -F first:last:len:conv logfile bookmarkfile [ pattern .. ]
fetchlog [-h|-V]
π DESCRIPTION π
so fetchlog shows you the last new messages of a logfile. it's giving tail(1) energy but with extra functionality for output formatting β like, tail could never, honestly. π
to show only the messages that showed up since the last time you called it, fetchlog uses a bookmark to remember which messages have already been fetched. iconic behaviour, fr fr.
here's the whole ritual: fetchlog scans backwards through logfile and collects all the messages, or optionally only the ones matching any of the pattern regex-style patterns you gave it. then it converts the found message lines for output. it stops scanning the moment one of these three things happens:
- the bookmark from bookmarkfile is reached π―
lencharacters are ready for output π- an error occurs π
fetchlog knows about rotated and uncompressed logfiles and keeps scanning in rotated logfiles by appending .0 to logfile, and if that file doesn't exist then .1, and so on upto .9, when scanning in rotated logfiles. and if a rotated logfile does not exist, scanning just stops without error. no drama. π§
π OPTIONS π
-fβ do not update the bookmark in bookmarkfile.-Fβ update the bookmark in bookmarkfile: sets the bookmark to the very last line fetched from logfile.- first β the first column of text
fetchlogwill read from logfile. lines shorter than first show up as a single newline. the column count starts with1. π’ - last β the maximum last column
fetchlogwill read from logfile. lines longer than last get cut off, and a~will be set at column last for output. the column count starts with1. βοΈ - len β the maximum number of characters
fetchlogwill output. if more thanlencharacters are available after cutting and conversion, the first line put out will start with'...'. π - conv β conversion: one ore more of characters
'bpsno3'. πb[brackets] β convert'<'and'>'to'('and')'for safe HTML output.p[percent] β convert'%'to'p'for safeprintf(1)output.s[shell] β convert'$','^', and the three quotes (backquote, doublequote, singlequote) and'|'to'_'and'\'to'/'. this conversion is useful when passing the result offetchlogto a shell command as a parameter. πn[newline] β convert newline characters to'\n'sequence to get a single line of output.o[ok message] β show'OK: no messages'if no new messages are available for output. β3[Nagios3] β output in multiline format required for plugins since Nagios3.
- logfile β absolute path to the unrotated logfile to fetch data from. the user needs read access to logfile. π
- bookmarkfile β absolute path to the file holding the bookmark. the user needs read access to the file when using option
-f, and write access plus permission to create files in the directory of bookmarkfile when using option-F(update bookmark).
if bookmarkfile does not exist, fetchlog assumes an infinite old bookmark. π°οΈ
- pattern β an extended regular expression pattern, see
re_format(7)for details. if one or more pattern are defined,fetchlogwill only pick lines where any of these pattern match. pattern matching is done after trimming the lines with respect to first and last and before any conversions takes place. in other words: pattern matching operates on data thatfetchlogshows when no conversion is set. π -hβ print help message-Vβ print version
π¦ MULTIPLE FETCHING π¦
fetching the same logfile with different bookmarks works without problem. simultanously fetching with option -F (update mode) using the same bookmark file works too, but unpredictable results will occur. π
for safety reasons bookmarkfile will never be opened for writing directly β instead a temporary file will be used and renamed to bookmarkfile when writing has finished. responsible queen behaviour, we love to see it. π
β‘ PERFORMANCE β‘
before opening logfiles for scanning, fetchlog first checks the modification time of logfile and compares this time with the modification time stored in bookmarkfile. if both timestamps are the same, then fetchlog exits with 0 (no messages). π―
otherwise the logfile(s) get mapped to memory step by step and are scanned backwards line by line until one of the end conditions become true. fetchlog uses the logfiles inode to distinguish different logs. spooky but correct. π₯
π NAGIOS π
fetchlog may be used as a local plugin for the Nagios network monitoring system to monitor a local logfile. it follows the calling convention for Nagios plugins if at least conversions on are set and len is 'short' enough for Nagios (330 prior to Nagios 3, 4000 since Nagios 3). it is recommended to use conversion s also, because shell metacharacters in fetched messages may confuse Nagios' notification system. π
Nagios 3 introduces a new interface for plugins sending out multiline output as fetchlog does. even with conversion 'n', Nagios reads this as a multiline message. to be compatible with Nagios 3 plugin format, enable conversion '3' also. output format is then:
SHORT_MESSAGE|\nMESSAGE_LINE_1\n...\nMESSAGE_LINE_N
where SHORT_MESSAGE will be the last line fetched MESSAGE_LINE_N. please see README.Nagios for details. π
when using fetchlog as a local plugin for Nagios, then exit status is as follows:
- OK β no new messages in logfile where found. the single line
'OK: no messages'will be send to stdout. β - WARNING β
fetchlogdetected an internal error while fetching. a one line error message starting with'ERROR: fetchlog:'is send to stdout. β οΈ - CRITICAL β new messages in logfile where found. a single line with the last new messages will be send to stdout. π¨
- UNKNOWN β
fetchlogwas called with wrong parameters. a multiline usage message is send to stdout. π€·
Nagios can monitor remote logfiles together with NET-SNMP and fetchlog using the check-snmp plugin. please read the README files coming with fetchlog how to setup this. π
π SNMP π
the motivation for fetchlog was to create a helper tool for NET-SNMP's snmpd to enable monitoring of remote kernel syslogs using SNMP. if configured properly, snmpd replies to a specific SNMP request with the output of an external helper program. with fetchlog using update mode -F and conversions on, one can peek at a remote syslog file and gets either 'OK: no messages' or one line with the new syslog messages appeared since the last SNMP request. π
because of some limitiations of SNMP itself and the monitoring applications using SNMP, the length of the SNMP reply must not exceed a specific size. to ease the integration of SNMP in monitoring software, it is useful to have the SNMP reply only consist of a single line of text rather than multiple lines. β¨
π COMPRESSING OUTPUT π
the syslog messages fetched can be compressed by increasing first to skip the timestamp and host entry from syslog. lowering last gives even more compression for long syslog lines. as a result one gets a very short message that gives an idea of what is going wrong. π
π₯ DIAGNOSTICS π₯
fetchlog sends all output and error messages to stdout. exit codes:
0β no new messages in logfile were found. if conversionois set, the single line'OK: no messages'will be send to stdout.1β an internal error infetchlogoccured. a one line error message will be send to stdout. the error message starts with'ERROR: fetchlog:'and shows detailed information about what went wrong. length limitation by parameterlenis applied β if an error message is too long, the last part will be cut off and a'~'is appended.2β new messages in logfile were found. the new messages will be send to stdout. if conversionnis set, a single line of text is send, else zero or more lines of converted syslog messages are send.3βfetchlogwas called with wrong parameters, a multiline usage message is print to stdout.
β οΈ Note: since version0.93the meanings of exit code1and2have been exchanged. so if you're reading old docs, bestie, don't get got. π
π«Ά AUTHOR π«Ά
Alexander Haderer, LoeScap Technology GmbH, Berlin - Germany
π SEE ALSO π
tail(1), cat(1), head(1), sed(1), re_format(7), syslogd(8), newsyslog(8)
- NET-SNMP β various tools relating to the Simple Network Management Protocol SNMP (NET-SNMP: formerly known as UCD-SNMP)
http://www.net-snmp.org - Nagios β a Network monitoring system
http://www.nagios.org - Nagios Plugins β plugins for Nagios
http://nagiosplug.sourceforge.net fetchloghomepage β download, support and bugtrackinghttp://fetchlog.sourceforge.net
π BUGS π
- Bookmarkfiles are not portable across plattforms or
fetchlogversions. - Logfiles are expected not to shrink.
fetchlogdoes not work with compressed logfiles.- Fetching when logfile rotation takes place may result in some messages to appear twice.
- If an regex error occurs during pattern matching, this error is silently ignored and will be handled as non-match. π
β LEGAL β
Nagios is a registered trademark of Ethan Galstad.
and that's the whole page, bestie π this was the fetchlog(1) manual, 23 Nov 2008 (1.2) edition β yeah she's a vintage queen from 2008, version 1.2, and she still slays. go fetch some logs. ππ¦β¨
π¦ where this page comes from
- fedora 43: fetchlog 1.4-30.fc43 Β· GPL-2.0-or-later
- fedora 44: fetchlog 1.4-31.fc44 Β· GPL-2.0-or-later
- Copyright (c) 2002, 2003, 2004, 2008 Alexander Haderer
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms