home: Move mosh cleanup script to local bin

This commit is contained in:
Alexander Kobjolke 2021-11-29 09:12:16 +01:00
parent bbecc3abd1
commit 33fb8148b2

16
home/local/bin/kill-old-mosh Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
mysession=$(cat /proc/self/sessionid)
count=0
while read pid _; do
session=$(cat /proc/$pid/sessionid)
if [ "$mysession" != "$session" ]; then
if kill $pid; then
echo 2>&1 "stale mosh session $pid killed"
count=$((count + 1))
fi
fi
done <<<$(ps -C mosh-server -o pid=,etimes= | sort -k 2 -r)
if [[ $count -eq 0 ]]; then
echo 2>&1 "No stale mosh session found"
fi