Killing multiple GNU screen sessions with the same name
If there are no other screen
sessions running you can use the "hard" way and just kill
them with killall screen
.
If you want to be nice you can iterate over your list of screen sessions and kill them one after another:
# screen -S foo && screen -S foo
[detached]
[detached]
# screen -ls
There are screens on:
8350.foo (Detached)
8292.foo (Detached)
2 Sockets in /tmp/screens/S-joschi.
# This is the interesting line. Just replace "foo" with the name of your session(s)
# for session in $(screen -ls | grep -o '[0-9]*\.foo'); do screen -S "${session}" -X quit; done
# screen -ls
No Sockets found in /tmp/screens/S-joschi.
screen -ls "$SESSION_NAME"
lists the full names of matching sessions on tab-indented lines. So you can iterate on these lines, extract the full names, and call the quit
command on each matching name.
SESSION_NAME='haydoz-script'
screen -ls "$SESSION_NAME" | (
IFS=$(printf '\t');
sed "s/^$IFS//" |
while read -r name stuff; do
screen -S "$name" -X quit
done
)