Skip to content

Instantly share code, notes, and snippets.

@rponte
Last active December 11, 2024 15:17
Show Gist options
  • Save rponte/08034bc74c4ecf0b1f8d16b70b5108d5 to your computer and use it in GitHub Desktop.
Save rponte/08034bc74c4ecf0b1f8d16b70b5108d5 to your computer and use it in GitHub Desktop.
Shell Script: One-line command combined with LLM (AI) to evaluate servers that are running locally and their criticality
# Brilliant one-liner
(echo "PID COMMAND PORT USER"; lsof -i -P -n | grep LISTEN | awk '{print $2, $1, $9, $3}' | sort -u | head -n 50; echo;) \
| column -t \
| llm "what servers are running on my machine and do some of them look like they could be orphaned things I can shut down"
# Maybe even more brilliant one liner
(echo "PID COMMAND PORT USER"; lsof -i -P -n | grep LISTEN | awk '{print $2, $1, $9, $3}' | sort -u | head -n 50) \
| column -t \
| llm "Analyze these processes. Output a JSON array of objects, where each object has 'pid', 'command', 'port', and 'reason' fields. Only include processes that look suspicious or potentially orphaned. Format as valid JSON." \
| jq -r '.[] | "kill \(.pid) # \(.command) on port \(.port): \(.reason)"'
@rponte
Copy link
Author

rponte commented Dec 11, 2024

@rponte
Copy link
Author

rponte commented Dec 11, 2024

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment