1

We're using freenx-server across login hosts where users access them via NoMachine clients from their end. Because of the many bugs associated with freenx and our budget not permitting the full commercial version, we end up with certain users having more than a few sessions as remnants when connections don't clean up after themselves upon termination (usually unintentional). Here's an example excerpt from /etc/nxserver.log:

Display Type             Session ID                       Options  Depth Screen         Status      Session Name
------- ---------------- -------------------------------- -------- ----- -------------- ----------- ------------------------------
33091   unix-gnome       189E20515FC5624507CAF25C836FB426 --D--PSA    24 885x843        Suspended   Connection to NXHost11 (user5) (Shadowed)
33053   unix-gnome       1DBD1E1131156842D72376675CE33E89 --D--PSA    24 1920x1123      Suspended   Connection to NXHost11 (user5) (Shadowed)
33111   unix-gnome       385B87A23EA908C0B4C6D00806D063B6 --D--PSA    24 871x538        Suspended   Connection to NXHost11 (user5) (Shadowed)
33082   unix-gnome       4D30B996528B752BFB1DE30240659230 --D--PSA    24 871x734        Running     Connection to NXHost11 (user5) (Shadowed)
33057   unix-gnome       57904D3FF28785366D962CDA35CBC6D4 --D--PSA    24 871x555        Running     Connection to NXHost11 (user5) (Shadowed)
33044   unix-gnome       6E338B9EE71D55DE4873ED83FCCB0AD9 --D--PSA    24 871x538        Suspended   Connection to NXHost11 (user5) (Shadowed)
33112   unix-gnome       8B2C9442496D09EFA0B78A13239D4EA0 --D--PSA    24 871x696        Suspended   Connection to NXHost11 (user5) (Shadowed)
33110   unix-gnome       8FD5158542B616E6B9B05B4E2425A6AF --D--PSA    24 871x831        Suspended   Connection to NXHost11 (user5) (Shadowed)
33014   unix-gnome       933CD67071697FBDC63D435E954BC8D6 --D--PSA    24 871x538        Running     Connection to NXHost11 (user5) (Shadowed)
33072   unix-gnome       B07D38F59367CE02ECA445B6EBBF84A1 --D--PSA    24 1138x667       Running     Connection to NXHost11 (user5) (Shadowed)
33000   unix-gnome       B58A633707EEC0C59C8A51EC9D688D3C --D--PSA    24 1920x1123      Running     Connection to NXHost11 (user5) (Shadowed)
33069   unix-gnome       BB78D40014DE5CF2A706536FF76FCFD8 --D--PSA    24 871x802        Suspended   Connection to NXHost11 (user5) (Shadowed)
33108   unix-gnome       C57D24C4AAC14F839E0A8C6B6C83D24E --D--PSA    24 1920x1123      Suspended   Connection to NXHost11 (user5) (Shadowed)
33070   unix-gnome       F90462D7CCEC82D5DDDA1E8C2CCE78E4 --D--PSA    24 1168x909       Suspended   Connection to NXHost11 (user5) (Shadowed)

To remove the sessions so the user's client doesn't continually freeze up, we have to manually remove them from /var/lib/nxserver/db/running/ - but the formatting is not the same:

[root@NXHost11 running]# pwd
/var/lib/nxserver/db/running
[root@NXHost11 running]# ls
sessionId{095675CAD6805301A215278C29E186F5}  sessionId{84A166F4F3D0B743357FA37751BDA786}
sessionId{0FA3E7C0B2914C66B8E468BE646D88F7}  sessionId{8B2C9442496D09EFA0B78A13239D4EA0}
sessionId{104750C53E17F5B87A9BFBC1E966B8D7}  sessionId{8CC40155C71AE6E7F73365DAFDCD2349}
sessionId{14B7F108B0A13635B7D697B26427D856}  sessionId{8ECBE26B9D5C10C44192C150FDA80158}
sessionId{15782E405134B2CF3BD09821CC3DC55C}  sessionId{8FADEDAE322A31585EB0DD8A30AB0285}
sessionId{180CA97293F95E625F12894B78FE100B}  sessionId{8FD5158542B616E6B9B05B4E2425A6AF}
sessionId{189E20515FC5624507CAF25C836FB426}  sessionId{92BCB8BA457267750FFE862EEB3C8CE6}
sessionId{18F86BA13166B94D0A80F10E3D3F220F}  sessionId{933CD67071697FBDC63D435E954BC8D6}
sessionId{195E394D40C21178D0ED4E5198B90792}  sessionId{9400C9D9D16CC0D4254DFAC45C9A52C9}
sessionId{1CD93CE30AD76937710823D0FAE15828}  sessionId{95DE940721837DF10BE3FEB1535DC78A}
sessionId{1DBD1E1131156842D72376675CE33E89}  sessionId{9A2A5A849295FC2EC4A9B7E27B53CBF7}
sessionId{1E1B5C326321775CCA05F2752CE17A8B}  sessionId{9D565E61FA3B1D81F9F1A0B185A0EC83}
sessionId{1FE7FD8EC70DC99652F214A3B5E905D1}  sessionId{A5877C91B948DFC24AF86EFB2495E527}
sessionId{22FAD34C0CC63CD959204669D8FDD9F0}  sessionId{A64443BB165B532521741D5D8F19EFAB}
sessionId{272CF217D5E8F56973743F86CAAF94BC}  sessionId{ABDC93271DF58FCE7DA7DBE7500C21B3}
sessionId{27FF7291F20965E10272A39B1FB8E4DC}  sessionId{AF6B1A42DD47C25FD176E60231A90DAD}
sessionId{2E7F640462E924284B079E10CC0E2E23}  sessionId{B07D38F59367CE02ECA445B6EBBF84A1}
sessionId{330CB4473B1AF6C948F2BFB9BDD2BADB}  sessionId{B2D860333DDD3B7FF35EA48BFF9ABD00}
sessionId{385B87A23EA908C0B4C6D00806D063B6}  sessionId{B42E37E4785B42342C4EB009D74B4EA0}
sessionId{389242121CE6E206584C2A45E236ABFF}  sessionId{B58A633707EEC0C59C8A51EC9D688D3C}
sessionId{3C4884BB99ADFF1FA18B039E88A864D1}  sessionId{B6C3CDE47C2371972A7536B854A931F4}
sessionId{3FED31A80C56BA9B038A6A765AED0C38}  sessionId{B779C01B1F1915E571B1639A481E9848}
sessionId{400753DEC565BB0DB52ED904137C463F}  sessionId{BB78D40014DE5CF2A706536FF76FCFD8}
sessionId{421C53FC39AE9D79E60E6055D2FC7DE8}  sessionId{C0740993AD5429567243033DD5451B0F}
sessionId{42F76BBDCE57874C8E3A0109E61BE37B}  sessionId{C0B5C4E91BFFC94A2ED8C399ADD264E4}
sessionId{43DBB2733414428C80DD68FA87D7C5B7}  sessionId{C57D24C4AAC14F839E0A8C6B6C83D24E}
sessionId{46A37999D33B0D66026C48D6D9C7B90A}  sessionId{C605F9961D8C4C6511CE11F375E2DAD2}
sessionId{4D30B996528B752BFB1DE30240659230}  sessionId{CD76B8B7119293B2CA6164D621BCA062}
sessionId{57904D3FF28785366D962CDA35CBC6D4}  sessionId{DAAA94C7D01E099A1D566AF0E44B23E4}
sessionId{58BFD388FBED5D39EED5D03A6BEB83B7}  sessionId{DBAE1C4AD9B0CEB956711384B9A4C503}
sessionId{5DC416CBE36DD68259246F21C4D12C63}  sessionId{DF866B06E27911C90130A4AC7F24E03C}
sessionId{6284D3EE9771A085520C12C5C089CB63}  sessionId{E112F0415D4B2B47D892FA16D83819AE}
sessionId{63F6B34AF4DD407E46CAB8D52EE1B00D}  sessionId{E767F74579682E357BCF9E8635658847}
sessionId{64CD7EC1A6156DFD992DCF6AA0D3D959}  sessionId{EB78959FD59424DAF2C965388A056AE3}
sessionId{6D570D2998E544DD2E2B4F68A9185377}  sessionId{ED560BFC6D38D0946AF3E0A453E8EBC2}
sessionId{6E338B9EE71D55DE4873ED83FCCB0AD9}  sessionId{EE11025659E3D66007357A870FB973AA}
sessionId{70556E711755D613445D72F505F5ACAA}  sessionId{EF819D2926EFF1DA0E0208578D282D28}
sessionId{7706DEA73E98C5997D61CA6BE49D2313}  sessionId{F1141CC7C189F45D4C6E1B5A805BA849}
sessionId{7723BB4A0C5CCE18A67D5D64235357AC}  sessionId{F5E6EC0AB1E015AE187CC30412291A70}
sessionId{787D6CE3EBA641706F3E07DD61159B24}  sessionId{F90462D7CCEC82D5DDDA1E8C2CCE78E4}
sessionId{7BD83901652D8F26B9D4B128D0021344}  sessionId{F904BF11478F62FF368ACAA9978F365B}
sessionId{8100B0CADB1369EB9573E9B986758545}  sessionId{F91EECDB9A7B9298763F3DB439205CFC}

The other issue is that there are other users on the same host that have running NoMachine sessions I can't close, or it'd be easy enough to just rm the whole directory's worth of sessions.

So, the question becomes, outside of manually removing each individual session ID:
rm sessionId{pasteletternumbercombinationhere}, would there be an easier way to accomplish this without impacting other users' sessions? It doesn't appear as though ps can display info I can script as the "handler" mechanism of freenx takes ownership and all sessionID files are nx:nx and not the username.

1

I hope I get this right: you want to remove all files with the sessionIDs listed as suspended? This would be

for SessionID in `sed -n '/Suspended/s/.*unix-gnome *\(\S*\).*/\1/p' /etc/nxserver.log`; do
  rm  /var/lib/nxserver/db/running/sessionId\{$SessionID\}
done

The sed script extracts the sessionIds from suspended sessions, for each the corresponding file is removed.

If this is not what you want, please clarify your question.

1

Since your data are nicely tabulated, a quick awk will do most of your work:

awk 'NR>2 && $7=="Suspended" {print "sessionID{"$3"}"}' /etc/nxserver.log | xargs rm -f

To see the list of files it would remove before running, use just:

awk 'NR>2 && $7=="Suspended" {print "sessionID{"$3"}"}' /etc/nxserver.log
0
cd "/var/lib/nxserver/db/running" && \
perl -lne '
   @F = unpack "x25A32x31A12";
   unlink "sessionId{$F[0]}" if $F[1] eq "Suspended";
' /etc/nxserver.log

unpack skips the first 25 chars, then grabs the next 32 = sessionId, and similarly grabs the Status field as well. Finally the unlink removes the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.