Skip to content

Instantly share code, notes, and snippets.

@marcogomiero
Created November 20, 2024 14:39
Show Gist options
  • Save marcogomiero/a9cc16fe09860a10f3e2daeb1795c458 to your computer and use it in GitHub Desktop.
Save marcogomiero/a9cc16fe09860a10f3e2daeb1795c458 to your computer and use it in GitHub Desktop.
A script to get rid off unwanted dbus storm fork with vault on bare metal (or VM)
#!/bin/bash
LOG_FILE="/var/log/kill_dbus.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
PROCESS_COUNT_BEFORE=$(ps -ef | grep -i dbus | grep -v grep | grep -v "$0" | wc -l)
PIDS=$(ps -ef | grep -i dbus | grep -v grep | grep -v "$0" | awk '{print $2}')
if [ -n "$PIDS" ]; then
echo "[$TIMESTAMP] - Killing PIDs: $PIDS" >> "$LOG_FILE"
echo "$PIDS" | xargs kill -9
EXIT_CODE=$?
else
echo "[$TIMESTAMP] - No dbus processes found to kill." >> "$LOG_FILE"
EXIT_CODE=0
fi
PROCESS_COUNT_AFTER=$(ps -ef | grep -i dbus | grep -v grep | grep -v "$0" | wc -l)
echo "[$TIMESTAMP] - Processes before: $PROCESS_COUNT_BEFORE, after: $PROCESS_COUNT_AFTER, exit code: $EXIT_CODE" >> "$LOG_FILE"
if [ $EXIT_CODE -ne 0 ]; then
echo "[$TIMESTAMP] - ERROR: Process termination failed with exit code $EXIT_CODE" >> "$LOG_FILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment