Created
March 30, 2024 02:22
-
-
Save rayvoelker/5507554bc89353ab8a0e968cfc879f29 to your computer and use it in GitHub Desktop.
monitor circmsg circulation override file for changes -- email just the changes
This file contains 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
#!/bin/bash | |
# Define file paths | |
CURRENT_FILE="/iiidb/errlog/circmsg" | |
PREVIOUS_FILE="/tmp/errlog-circmsg-prev" | |
# Check if the previous file snapshot exists | |
if [ ! -f "$PREVIOUS_FILE" ]; then | |
# If not, create it and exit, as we can't compare yet | |
cp "$CURRENT_FILE" "$PREVIOUS_FILE" | |
exit 0 | |
fi | |
# Compute checksums | |
CURRENT_CHECKSUM=$(md5sum "$CURRENT_FILE" | awk '{print $1}') | |
PREVIOUS_CHECKSUM=$(md5sum "$PREVIOUS_FILE" | awk '{print $1}') | |
# Compare checksums to see if the file has changed | |
if [ "$CURRENT_CHECKSUM" != "$PREVIOUS_CHECKSUM" ]; then | |
# Use diff to capture changes | |
DIFF_OUTPUT=$(diff "$PREVIOUS_FILE" "$CURRENT_FILE") | |
# Parse the diffs (implement your parsing logic here) | |
# PARSED_DIFFS=$(echo "$DIFF_OUTPUT" | your_parsing_command_here) | |
# For the sake of example, let's just assign DIFF_OUTPUT to PARSED_DIFFS | |
PARSED_DIFFS="$DIFF_OUTPUT" | |
# Check if there are any diffs to send | |
if [ -n "$PARSED_DIFFS" ]; then | |
# Send an email with the parsed diffs | |
# Replace the next line with your email command | |
echo "$PARSED_DIFFS" | mail -s "`circmsg` File Changes Detected" ilshelp@chpl.org | |
fi | |
# Update the previous file snapshot for next comparison | |
cp "$CURRENT_FILE" "$PREVIOUS_FILE" | |
else | |
echo "No changes detected." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment