-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvncstatus
More file actions
executable file
·44 lines (39 loc) · 1.1 KB
/
vncstatus
File metadata and controls
executable file
·44 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python
from __future__ import print_function
import subprocess
import re
cmd = 'ps -C Xvnc -o args'
cmdargs = cmd.split()
data = subprocess.check_output(cmdargs)
lines = data.split("\n")
names = []
numbers = []
for ln in lines:
if ln == 'COMMAND':
continue
# oh boy! parsing!
# the format of the args are executable, desktop args as key value pairs
# keys start with a '-'
curargs = ln.split()
if len(curargs) < 3:
continue
desktop = curargs[1]
mtch = re.search("\:(\d+)",desktop)
if mtch:
numbers.append(mtch.group(1))
nextargs = False
name = ''
for n in range(2,len(curargs)):
mtch = re.search("\A-",curargs[n])
if curargs[n] == '-desktop':
nextargs = True
name = ''
elif nextargs and mtch is None:
nmtch = re.search("\:\d+",curargs[n])
if nmtch is None:
name = name +' ' + curargs[n]
elif nextargs and mtch :
names.append(name)
nextargs = False
for n in range(0,len(numbers)):
print ( numbers[n], names[n])