Make user history cleaning optional in trace eraser

User bash history cleaning is now optional with a prompt, since most users only work as root.

Changes:
• Added user count detection
• Prompts: "Clean user bash histories too? (y/n) [n]"
• Default is "no" (skip user histories)
• If no users exist, automatically skips
• Only cleans root history by default (faster, covers 99% of use cases)

This makes the script faster and more sensible for typical usage where only root is used to run the toolkit.
This commit is contained in:
cschantz
2025-11-10 22:20:11 -05:00
parent b3773ee37c
commit 762b5ba958
+20 -2
View File
@@ -73,9 +73,22 @@ if [ -f ~/.bash_history ]; then
history -w history -w
fi fi
# Clean bash history for all users # Clean bash history for all users (optional - skip if only root is used)
echo "→ Checking user histories..." echo "→ Checking user histories..."
user_count=0
for user_home in /home/*; do for user_home in /home/*; do
[ -d "$user_home" ] && user_count=$((user_count + 1))
done
if [ "$user_count" -eq 0 ]; then
echo " ✓ No user accounts found (skipped)"
else
echo " Found $user_count user account(s)"
echo ""
read -p " Clean user bash histories too? (y/n) [n]: " clean_users
if [ "$clean_users" = "y" ] || [ "$clean_users" = "Y" ]; then
for user_home in /home/*; do
if [ -f "$user_home/.bash_history" ]; then if [ -f "$user_home/.bash_history" ]; then
username=$(basename "$user_home") username=$(basename "$user_home")
echo " → Cleaning history for $username..." echo " → Cleaning history for $username..."
@@ -94,7 +107,12 @@ for user_home in /home/*; do
echo " ✓ Cleared (file had < 50 entries)" echo " ✓ Cleared (file had < 50 entries)"
fi fi
fi fi
done done
else
echo " ✓ Skipped user histories (only root cleaned)"
fi
fi
echo ""
# Clean system logs (pattern-based for logs, not history) # Clean system logs (pattern-based for logs, not history)
echo "→ Cleaning system logs..." echo "→ Cleaning system logs..."