Skip to content

Instantly share code, notes, and snippets.

@MHebes
Created January 7, 2021 02:47
Show Gist options
  • Save MHebes/873bb00e6eb6d9549486da64cda6e8a5 to your computer and use it in GitHub Desktop.
Save MHebes/873bb00e6eb6d9549486da64cda6e8a5 to your computer and use it in GitHub Desktop.
Simple bash script to sanitize the logs from your plex server before posting them somewhere
#!/bin/sh
# Script for removing emails, IPs, and other sensitive info from log files.
if [ $# -eq 0 ]; then
echo "Usage: $0 [-i] [file ...]"
exit 1
fi
# Extended, case-insensitive regex patterns for things you want to remove
sanitize=(
"Martin"
"mhebes"
"mywindowsusername"
"C:"
"D:"
"My Server's Friendly Name"
"The Name of The Movie( \(2004\))?"
)
# Create replacement pattern from array
pat=""
for i in ${!sanitize[@]}; do
pat="${pat};s/${sanitize[$i]}/[REDACTED]/gi"
done
# 1. Replaces emails with MYEMAIL@example.com
# 2. Replace the first two octects for IP addresses with XXX's (e.g. 192.168.1.50 -> XXX.XXX.1.50)
# 3. Replaces anything in the sanitize list with [REDACTED]
sed -r \
-e "s/([[:alnum:]_.-]+@[[:alnum:]_.-]+?\.[[:alpha:].]{2,6})/MYEMAIL@example.com/g" \
-e "s/\b[0-9]{1,3}\.[0-9]{1,3}\.([0-9]{1,3}\.[0-9]{1,3})\b/XXX.XXX.\1/g" \
-e "${pat}" \
"$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment