Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Using a shell script, how can you tell if a screen is running using shell scripts?

For example, using pseudocode:

IF (screen.screenname.running == TRUE)

or something like that.

share|improve this question
    
what's your eventual goal? (I wonder if you are going to say that you want to do something which can be achived instead by screen -d -R or pgrep or ? –  stew Feb 17 '12 at 15:56
    
One way to tell the GNU screen is running is to check the TERM variable: if the remote server recognizes the screen terminal, then this will work. However, this is not a reliable indicator: one could use vt100 just as well. (In my session, I see TERM=screen-bce.) However, I concur with @stew: What are you trying to do? –  Mei Feb 17 '12 at 16:42
    
@David me? just help him with his question :) –  stew Feb 17 '12 at 16:44
    
@stew: Nah: I'm asking the original poster the same question you did. That's all. –  Mei Feb 17 '12 at 17:51
add comment

1 Answer

if `screen -ls <screenname> | grep -q "There is a screen on"`; then
    echo "<screenname> is running"
fi
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.