Resume Unknown Screen

Sometimes you know that there is an instance of an application running in a screen but you are not sure about the exact screen name and

screen -x

returns a tedious list. Maybe I still have no clue about how to use screen to the fullest, but here is a function I use in a script on my shell account to resume screens:

Resumes a screen instance of the program name given as the first argument

resume_application() {
        screen -rd $(screen -list|egrep $(ps aux|egrep "SCREEN ${1}"|egrep "^[($(id|awk '{print $1}'|cut -d'=' -f2|cut -b -4))|($(whoami))]"|head -n 1|awk '{print $2}')|head -n 1|awk '{print $1}')
}

Resuming a screen instance of centericq

resume_application "centericq"

Leave a Reply