vmtools/vmlist
cecilkorik 7b51226796 initial import
--HG--
branch : vmtools
2011-03-05 08:34:41 +00:00

39 lines
783 B
Python
Executable file

#!/usr/bin/python
import os, sys
fd = open('/srv/vmlist', 'r')
auto_only = False
running_only = False
show_pids = False
if len(sys.argv) > 1 and sys.argv[1] == '-a':
auto_only = True
if len(sys.argv) > 1 and sys.argv[1] == '-r':
running_only = True
if len(sys.argv) > 1 and sys.argv[1] == '-p':
show_pids = True
for line in fd:
line = line.strip()
if not line:
continue
ls = line.split(' ')
if auto_only and ls[3] == '0':
continue
pid = None
if running_only or show_pids:
if not os.path.exists('/var/run/vbox/%s' % (ls[0],)):
continue
pid = open('/var/run/vbox/%s' % (ls[0],), 'r').read()
procfile = "/proc/%s/cmdline" % (pid,)
if not os.path.exists(procfile):
continue
if show_pids:
print "%s %s" % (ls[0], pid)
else:
print ls[0]
fd.close()