Skip to content

Instantly share code, notes, and snippets.

@nisshiee
Last active December 21, 2015 16:59
Show Gist options
  • Save nisshiee/6337639 to your computer and use it in GitHub Desktop.
Save nisshiee/6337639 to your computer and use it in GitHub Desktop.
screen -lsの出力を見て適切にオプションつけてscreenを起動してくれるスクリプト
#!/bin/bash
STATUS=`screen -ls`
new_session() {
exec screen
}
detach_and_reattach() {
exec screen -d -r
}
multi_attach() {
exec screen -x
}
reattach() {
exec screen -r
}
echo $STATUS | grep 'No Sockets found' > /dev/null 2>&1
if [ $? -eq 0 ]; then
new_session
exit 0
fi
echo $STATUS | grep '1 Socket in' > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo $STATUS | grep 'Attached' > /dev/null 2>&1
if [ $? -eq 0 ]; then
multi_attach
exit 0
fi
echo $STATUS | grep 'Detached' > /dev/null 2>&1
if [ $? -eq 0 ]; then
reattach
exit 0
fi
echo '[ERROR] parse `screen -ls` error.'
echo "$STATUS"
exit 1
fi
echo '[WARN] more than 1 session found. Please reconnect manually.'
echo "$STATUS"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment