File: //data/fileMonitor/checkFileChange.sh-singleFile
#!/bin/bash
# Configuration
FILE="index.php" # File to monitor
RECORD_FILE="mod_time_record.log" # File to store previous hash and modification time
# Check if file exists
if [[ ! -f "$FILE" ]]; then
echo "Error: $FILE does not exist!"
exit 1
fi
# Get current hash and modification time
CURRENT_HASH=$(sha256sum "$FILE" | awk '{print $1}')
CURRENT_MOD_TIME=$(stat -c %y "$FILE")
# Initialize record file if it doesn't exist
if [[ ! -f "$RECORD_FILE" ]]; then
echo "$CURRENT_HASH|$CURRENT_MOD_TIME" > "$RECORD_FILE"
echo "Monitoring started. Initial values recorded."
exit 0
fi
# Read last record
IFS="|" read LAST_HASH LAST_MOD_TIME < "$RECORD_FILE"
# Check for changes
if [[ "$CURRENT_HASH" != "$LAST_HASH" ]]; then
echo "File changed!"
echo "Last Modification Time: $LAST_MOD_TIME"
echo "Current Modification Time: $CURRENT_MOD_TIME"
# Send notification via static curl command
curl --location --request POST 'https://marketing.wp.karmanye.in/api/Karmanye/send-message' \
--header 'Content-Type: application/json; charset=utf-8' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer $2b$10$f7yAQHm3Y1eOxs92aiEJ9eohJ0AdUQ2YwXxUARzk3sVLgKIVw0k2q' \
-d "{
\"phone\": \"919033595842\",
\"message\": \"šØ *Security Alert: File Change Detected* šØ\n\nš *File*: index.php\nš *Previous Modification Time*: \`$LAST_MOD_TIME\`\nš *Current Modification Time*: \`$CURRENT_MOD_TIME\`\n\nā ļø *Immediate Attention Required!*\n\nPlease verify the change to ensure it's authorized.\"
}"
# Update the record file
echo "$CURRENT_HASH|$CURRENT_MOD_TIME" > "$RECORD_FILE"
else
echo "No changes detected."
fi