mirror of
https://github.com/nickolaj-jepsen/nixos.git
synced 2026-01-23 08:26:49 +01:00
feat: add more scripts
This commit is contained in:
parent
cd289da742
commit
575db8e773
7 changed files with 99 additions and 9 deletions
25
modules/scripts/port-kill.bash
Normal file
25
modules/scripts/port-kill.bash
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PORT=$1
|
||||
if [ -z "$PORT" ]; then
|
||||
echo "Usage: port-kill <port>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# lsof returns exit code 1 if no files found
|
||||
PID=$(lsof -t -i:"$PORT" || true)
|
||||
|
||||
if [ -z "$PID" ]; then
|
||||
echo "No process found on port $PORT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COMMAND=$(ps -p "$PID" -o comm=)
|
||||
echo "Process '$COMMAND' (PID $PID) is using port $PORT."
|
||||
read -p "Kill? [y/N] " -n 1 -r
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
kill "$PID"
|
||||
echo "Killed."
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue