Last active
December 11, 2024 15:17
-
-
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
This file contains 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
# 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)"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://x.com/simonw/status/1866717521644228801