#!/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()