Created
July 20, 2025 20:55
-
-
Save delorenj/ad49a8058aa5659f9952b592b74bf3cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "🔍 LSOF DETECTIVE MODE" | |
echo "Watching for .clinerules-architect files and immediately identifying the creator..." | |
echo "" | |
WATCH_DIR="/home/delorenj/code" | |
FILENAME=".clinerules-architect" | |
inotifywait -m -r --format '%w%f' -e create "$WATCH_DIR" | while read FILE; do | |
if [[ "$(basename "$FILE")" == "$FILENAME" ]]; then | |
echo "🚨 FILE CREATED: $FILE" | |
notify-send "New .clinerules-architect file" "$FILE" --icon=dialog-information | |
paplay /usr/share/sounds/freedesktop/stereo/complete.oga 2>/dev/null || true | |
# Get process info using lsof | |
sleep 0.1 # Give the process a moment to finish creating the file | |
CULPRIT=$(sudo lsof "$FILE" 2>/dev/null | tail -n +2 | awk '{print $2, $1}') | |
if [[ -n "$CULPRIT" ]]; then | |
PID=$(echo "$CULPRIT" | awk '{print $1}') | |
PROC=$(echo "$CULPRIT" | awk '{print $2}') | |
EXE=$(readlink -f /proc/$PID/exe 2>/dev/null || echo "unknown") | |
CMD=$(cat /proc/$PID/cmdline 2>/dev/null | tr '\0' ' ' || echo "unknown") | |
echo "🕵️ CULPRIT IDENTIFIED:" | |
echo " Process: $PROC (PID: $PID)" | |
echo " Executable: $EXE" | |
echo " Command: $CMD" | |
echo " Parent Process: $(ps -o ppid= -p $PID | tr -d ' ')" | |
echo "" | |
else | |
echo "⚠️ Process already exited, checking recent file modifications..." | |
# Fallback: check recent processes that touched the directory | |
sudo sysdig -p "%proc.name %proc.exepath" "fd.name contains \"$FILENAME\"" 2>/dev/null | tail -5 | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment