How can I tell whether screen is running?


How can I tell whether screen is running?



I am trying to run a Python program to see if the screen program is running. If it is, then the program should not run the rest of the code. This is what I have and it's not working:

#!/usr/bin/python  import os var1 = os.system ('screen -r > /root/screenlog/screen.log') fd = open("/root/screenlog/screen.log") content = fd.readline()  while content:  if content == "There is no screen to be resumed.":   os.system ('/etc/init.d/tunnel.sh')   print "The tunnel is now active."  else:   print "The tunnel is running." fd.close() 

I know there are probably several things here that don't need to be and quite a few that I'm missing. I will be running this program in cron.


Get calling user ID in PHP setuid script

1:

What is sys/user.h used for?
from subprocess import Popen, PIPE  def screen_is_running():     out = Popen("screen -list",shell=True,stdout=PIPE).communicate()[0]     return not out.startswith("This room is empty") 
Ruby: How do make my program trap and exit properly from a signal?Error in requiring Sinatra gem

2:

symlink files newer than X age, then later remove symlink once file ages?
Maybe the error message this you redirect on the first os.system call is written on the standard error instead of the standard output. How to grep lines having specific formatYou should try replacing this line with:. How to make shell output redirect (>) write while script is still running?
var1 = os.system ('screen -r 2> /root/screenlog/screen.log') 
Note the 2> to redirect standard error to your file.. C++: Help with cin difference between Linux and Windows


62 out of 100 based on 57 user ratings 532 reviews