次のbashコマンド(Ubuntu 18.04で実行)は、各XRDPセッションの解像度(形状)を除いて、必要なXRDP情報をテーブルに表示します。
{ echo "user pid Xdisplay port"; { ps -ef | awk '/Xvnc :[[:digit:]]+/ {print $1,$2,$9}' | while read tu tpid tvnc; do sudo netstat -tlpn | awk -v "tpid=${tpid}" '$0 ~ tpid {print $4;}' | sed -r -e 's/^.*://;' -e "s/^/${tu} ${tpid} ${tvnc} /;" ; done ; } | sort -k3 ; } | column -c4 -t
たとえば、出力を提供します。
user pid Xdisplay port
baz 127229 :11 5911
bar 27817 :12 5912
baz 48659 :13 5913
ユーザー名、pid、Xdisplay、およびポート番号の既存の詳細に加えて、RDPセッション解像度(形状)を表示するためにどのように使用できますか?
希望の出力フォーマット
user pid Xdisplay port geometry
bar 108415 :1 5901 1440x900
foo 17056 :2 5902 1920x1200
baz 127229 :11 5911 1920x1200
bar 27817 :12 5912 2560x1440
baz 48659 :13 5913 1920x1200
出力例ps -ef | grep 'Xvnc'
foo 17056 1 0 Jun18 ? 07:00:08 Xvnc4 :2 -desktop myubuntupc:2 (foo) -auth /home/foo/.Xauthority -geometry 1920x1200 -depth 16 -rfbwait 30000 -rfbauth /home/foo/.vnc/passwd -rfbport 5902 -pn -fp /usr/X11R6/lib/X11/fonts/Type1/,/usr/X11R6/lib/X11/fonts/Speedo/,/usr/X11R6/lib/X11/fonts/misc/,/usr/X11R6/lib/X11/fonts/75dpi/,/usr/X11R6/lib/X11/fonts/100dpi/,/usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/ -co /etc/X11/rgb
bar 27817 27805 0 Aug06 ? 00:00:21 Xvnc :12 -geometry 2560x1440 -depth 24 -rfbauth /home/bar/.vnc/sesman_bar_passwd -bs -ac -nolisten tcp -localhost -dpi 96
baz 48659 48657 12 Sep02 ? 12:16:26 Xvnc :13 -auth .Xauthority -geometry 1920x1200 -depth 32 -rfbauth /home/baz/.vnc/sesman_passwd-baz@myubuntupc:13 -bs -nolisten tcp -localhost -dpi 96
bar 108415 1 0 Jul16 ? 02:09:36 Xvnc4 :1 -desktop myubuntupc:1 (bar) -auth /home/bar/.Xauthority -geometry 1440x900 -depth 16 -rfbwait 30000 -rfbauth /home/bar/.vnc/passwd -rfbport 5901 -pn -fp /usr/X11R6/lib/X11/fonts/Type1/,/usr/X11R6/lib/X11/fonts/Speedo/,/usr/X11R6/lib/X11/fonts/misc/,/usr/X11R6/lib/X11/fonts/75dpi/,/usr/X11R6/lib/X11/fonts/100dpi/,/usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/ -co /etc/X11/rgb
bar 115933 115125 0 15:17 pts/29 00:00:00 grep --color=auto Xvnc
baz 127229 127227 0 Sep01 ? 00:02:56 Xvnc :11 -auth .Xauthority -geometry 1920x1200 -depth 16 -rfbauth /home/baz/.vnc/sesman_passwd-baz@myubuntupc:11 -bs -nolisten tcp -localhost -dpi 96
出力sudo netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:41603 0.0.0.0:* LISTEN 88147/ssh
tcp 0 0 127.0.0.1:38609 0.0.0.0:* LISTEN 87886/ssh
tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN 108415/Xvnc4
tcp 0 0 0.0.0.0:6002 0.0.0.0:* LISTEN 17056/Xvnc4
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN 7966/dnsmasq
tcp 0 0 127.0.0.1:3350 0.0.0.0:* LISTEN 106498/xrdp-sesman
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 43940/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 17827/cupsd
tcp 0 0 127.0.0.1:5911 0.0.0.0:* LISTEN 127229/Xvnc
tcp 0 0 127.0.0.1:5912 0.0.0.0:* LISTEN 27817/Xvnc
tcp 0 0 127.0.0.1:5913 0.0.0.0:* LISTEN 48659/Xvnc
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 105821/master
tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN 106523/xrdp
tcp6 0 0 ::1:41603 :::* LISTEN 88147/ssh
tcp6 0 0 :::5901 :::* LISTEN 108415/Xvnc4
tcp6 0 0 :::5902 :::* LISTEN 17056/Xvnc4
tcp6 0 0 ::1:38609 :::* LISTEN 87886/ssh
tcp6 0 0 :::22 :::* LISTEN 43940/sshd
tcp6 0 0 ::1:631 :::* LISTEN 17827/cupsd
tcp6 0 0 :::25 :::* LISTEN 105821/master
答え1
次のことを証明するためにcat netstatout
代わりに使用する:sudo netstat -tlpn
cat psout
ps -ef
$ cat tst.awk
BEGIN {
OFS = "\t"
print 0, 0, "user", "pid", "Xdisplay", "port", "geometry"
}
NR==FNR {
port = $4; sub(/.*:/,"",port)
pid = $NF; sub("/.*","",pid)
pid2port[pid] = port
next
}
/Xvnc[0-9]* :[[:digit:]]/ {
port = pid2port[$2]
match($0,/geometry [^ ]+/)
geometry = substr($0,RSTART+9,RLENGTH-9)
display = $9; sub(/:/,"",display)
print 1, display, $1, $2, $9, port, geometry
}
。
$ awk -f tst.awk <(cat netstatout) <(cat psout) | sort -k1,1n -k2,2n | cut -f3- | column -t
user pid Xdisplay port geometry
bar 108415 :1 5901 1440x900
foo 17056 :2 5902 1920x1200
baz 127229 :11 5911 1920x1200
bar 27817 :12 5912 2560x1440
baz 48659 :13 5913 1920x1200