A script to edit log files, it can remove the username, UID, a specefic string, remove logs and remove the netinfo backup, it's not working.
#!/bin/bash
remove_logs() {
find -f /var/log -f /Library/Logs -f /Users/*/Library/Logs \! -iname "*.gz" \! -name ".DS_Store" | while read file ; do
sed -e "s/${USER_ID}//g" -e "s/${USER_NAME}//g" -e "s/${USER_STRING}//g" "${file}" > "${file}.tmp" && mv "${file}.tmp" "${file}"
done
}
USER_ID="afghanistanbannanastand"
USER_NAME="${USER_ID}"
USER_STRING="${USER_ID}"
YES=""
echo "Enter your password to check for sudo permission" ;
AMIN=$(sudo -l | cut -d: -f2 | sed "s/>//g" | sed "s/ //g" | sed "s/(.*)//g" | uniq)
if [ $AMIN = ALL ]; then
if [ "$UID" != "0" ]; then
echo "Not root. Trying to remove logs with sudo.";
exec sudo /bin/bash "${0}";
else
echo -n "Do you want to delete your username and uid from the logs [y or n]? "
read YES_NO && echo "${YES_NO}" | tr "A-Z" "a-z" && [ "${YES_NO:0:1}" = "y" ] && USER_ID="${UID}" && USER_NAME="${USER}"
echo "Enter a string that you want to delete from the logs or press return to skip."
read USER_STRING && [ -z "${USER_STRING}" ] && USER_STRING="afghanistanbannanastand"
echo "Do you want to remove all log files? y to accept return to skip."
read YN
echo "Do you want to remove the netinfo backups (dangerous but reccomended if account is being deleted)[y or n]"
read NY
remove_logs
if [ ${YN} = "y" ]; then
find /var/log -type f \! -name ".DS_Store" | while read files ; do srm ${files} ; done
fi
if [ ${NY} = "y" ]; then
sudo srm /private/var/backups/local.nidump
fi
fi
fi
exit 0
It seems to work, but when I look over the logs I can see things that shouldn't be there, And I'm not sure why, any help would be appreciated.