helper: Print pid of killed mosh sessions

This commit is contained in:
Alexander Kobjolke 2021-11-16 17:30:24 +01:00
parent d2afe13425
commit bbecc3abd1

View file

@ -4,13 +4,13 @@ count=0
while read pid _; do
session=$(cat /proc/$pid/sessionid)
if [ "$mysession" != "$session" ]; then
kill $pid
count=$((count + 1))
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"
else
echo 2>&1 "$count stale mosh session(s) killed"
fi