nixos-config/home/alex/local/bin/kill-old-mosh

16 lines
413 B
Bash
Executable file

#!/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