Created
November 12, 2025 12:35
-
-
Save tonusoo/e58728cdd0785978b00593568d5b6687 to your computer and use it in GitHub Desktop.
logtail functionality for journalctl versions older than 242 not supporting the "--cursor-file" option
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| get_journal_logs() { | |
| log_type="$1" | |
| if [[ "$log_type" == "system" ]]; then | |
| args+=( "--dmesg" ) | |
| elif [[ "$log_type" == "apache" ]]; then | |
| args+=( "--unit=apache2" ) | |
| fi | |
| cursor_file="$HOME/.journal_cursor_${log_type}" | |
| if [[ -f "$cursor_file" ]]; then | |
| read -r cursor < "$cursor_file" | |
| [[ -n "$cursor" ]] && args+=( "--after-cursor" "$cursor" ) | |
| fi | |
| args+=( "--no-pager" ) | |
| args+=( "--show-cursor" ) | |
| args+=( "--lines=1000" ) | |
| while read -r logline; do | |
| case "$logline" in | |
| "-- cursor:"*) | |
| echo "${logline#-- cursor: }" > "$cursor_file" | |
| ;; | |
| # Supress the "-- No entries --" message. | |
| # Avoid using --quiet which suppresses all | |
| # informational messages. | |
| "-- No entries --") | |
| ;; | |
| *) | |
| echo "$logline" | |
| ;; | |
| esac | |
| done < <(journalctl "${args[@]}") | |
| } | |
| get_journal_logs "system" | \ | |
| mailx --discard-empty-messages -s "system log check" [email protected] | |
| get_journal_logs "apache" | \ | |
| mailx --discard-empty-messages -s "Apache log check" [email protected] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment