LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-13-2016, 01:53 AM   #1
avihuh
LQ Newbie
 
Registered: Dec 2016
Posts: 19

Rep: Reputation: Disabled
identity session in multiple vnc servers


Hi,
I would like to create automation tool (bash file) that will run automatically in all our vnc-servers and will check by user where he has open sessions
Code:
ps aux | grep vnc | grep $user
how to start?
thnks
 
Old 12-13-2016, 03:31 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Welcome to the forum

The utility pgrep can find the process id for you based on your search criteria.

Code:
pgrep -x vnc -u $user
That will give you a list of the process ids for the processes with the exact name "vnc". Which VNC server are they running, that will tell you which name to look for.
 
Old 12-13-2016, 04:44 AM   #3
avihuh
LQ Newbie
 
Registered: Dec 2016
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Welcome to the forum

The utility pgrep can find the process id for you based on your search criteria.

Code:
pgrep -x vnc -u $user
That will give you a list of the process ids for the processes with the exact name "vnc". Which VNC server are they running, that will tell you which name to look for.
I tried
Code:
pgrep -x vnc -u avihuh
couldn't find process
when I tried :
Code:
ps aux | grep avihuh | grep vnc
he found
what I'm doing wrong?
 
Old 12-13-2016, 04:50 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Your search name is not found. The vnc has to be the exact name of the VNC server program that is running.

What is the output of the following?

Code:
pgrep -l -u avihuh vnc
That searches for any running program with "vnc" anywhere in the name for the user "avihuh"
 
Old 12-13-2016, 04:53 AM   #5
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
The name might not be **exactly** vnc. Remove the -x (check man pgrep)
Check with: ps ax|grep vnc

Welcome to Linux! (IF you want, tell us a tiny bit about your 'distro', &Linux goals/interest)

p.s. A different idea/concept (see man ...): netstat -tap |egrep 'vnc|ESTAB'
(grep vnc /etc/services) Enjoy!

Last edited by Jjanel; 12-13-2016 at 05:15 AM.
 
Old 12-13-2016, 05:09 AM   #6
avihuh
LQ Newbie
 
Registered: Dec 2016
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Your search name is not found. The vnc has to be the exact name of the VNC server program that is running.

What is the output of the following?

Code:
pgrep -l -u avihuh vnc
That searches for any running program with "vnc" anywhere in the name for the user "avihuh"
Code:
17499 Xvnc
17526 vncconfig
 
Old 12-13-2016, 05:11 AM   #7
avihuh
LQ Newbie
 
Registered: Dec 2016
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Jjanel View Post
The name might not be **exactly** vnc. Remove the -x (check man pgrep)
Check with: ps ax|grep vnc

Welcome to Linux! (IF you want, tell us a tiny bit about your 'distro', &Linux goals/interest)

p.s. A different idea/concept (see man ...): netstat -tap |grep vnc
(grep vnc /etc/services) Enjoy!
I'm familiar with what u suggested I will explain what I need
I need to create a script that will check in multiple servers if there is session for specific user
 
Old 12-13-2016, 05:13 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Ok. Then you can find just the PIDs of the instances of Xvnc by using that exact name in your query:

Code:
pgrep -u avihuh -x Xvnc
As Jjannel suggest, perusing the manual page for pgrep can be a good idea. The -x will require an exact match but that is eventually what you need to avoid false matches.
 
Old 12-13-2016, 05:16 AM   #9
avihuh
LQ Newbie
 
Registered: Dec 2016
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Ok. Then you can find just the PIDs of the instances of Xvnc by using that exact name in your query:

Code:
pgrep -u avihuh -x Xvnc
As Jjannel suggest, perusing the manual page for pgrep can be a good idea. The -x will require an exact match but that is eventually what you need to avoid false matches.
actually my need is the session number, and I need it in multiple servers this command is for specific server
 
Old 12-13-2016, 05:20 AM   #10
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by avihuh View Post
actually my need is the session number, and I need it in multiple servers this command is for specific server
Can you copy one line with that information as it is shown from regular ps and paste it here? You might need awk
 
Old 12-13-2016, 05:31 AM   #11
avihuh
LQ Newbie
 
Registered: Dec 2016
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
Can you copy one line with that information as it is shown from regular ps and paste it here? You might need awk
attaced
Attached Thumbnails
Click image for larger version

Name:	Capture.PNG
Views:	10
Size:	754 Bytes
ID:	23746  
 
Old 12-13-2016, 05:39 AM   #12
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Oh! I'm learning here! I *wrongly* thought you meant PID (by "session number"). This search:
vnc "session number"

A question on the "multiple servers": did you want this to run *from* a 'master' [server],
or did you want this to run 'autonomously' on all systems? (Do you want to collect the results?)
I'm thinking of concepts like nagios (tho I don't know nagios), vs. [topic search]:
"run command on multiple systems"? (like via ssh; do you have this setup already?)

Best wishes... Let us know how it goes...
 
Old 12-13-2016, 05:44 AM   #13
avihuh
LQ Newbie
 
Registered: Dec 2016
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Jjanel View Post
Oh! I'm learning here! I *wrongly* thought you meant PID (by "session number"). This search:
vnc "session number"

A question on the "multiple servers": did you want this to run *from* a 'master' [server],
or did you want this to run 'autonomously' on all systems? (Do you want to collect the results?)
I'm thinking of concepts like nagios (tho I don't know nagios), vs. [topic search]:
"run command on multiple systems"? (like via ssh; do you have this setup already?)

Best wishes... Let us know how it goes...
run from master server
collect the results
we already have multiples vnc servers here
and there are cases that someone forgot his port or event server so with that script I will be able to locate
 
Old 12-13-2016, 05:54 AM   #14
Jjanel
Member
 
Registered: Jun 2016
Distribution: any&all, in VBox; Ol'UnixCLI; NO GUI resources
Posts: 999
Blog Entries: 12

Rep: Reputation: 364Reputation: 364Reputation: 364Reputation: 364
Oh, I see now! I see *two* pieces to work on here:
1) get it working locally (research/web-search: get vnc session info)
(`vncserver -list` ?)
2) How will you 'access' the *multiple* other servers?
(do you have this setup/working already? [for any/simple-test command])

Best wishes.... Hopefully other LQ'ers, with more expertise on this than me, will come along.

Last edited by Jjanel; 12-13-2016 at 06:27 AM.
 
Old 12-13-2016, 05:55 AM   #15
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Ok. That's doable. Can you do ps auwx | grep Xvnc | head -n 1 and put it in [code] [/code] tags so we can see it as you see it on your set up?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple X-servers, multiple graphics adapters, single-seat (kind of tutorial) bluebox Linux - Desktop 6 06-07-2017 08:20 AM
How to have multiple identity for some node in ns2 Miralimk Programming 1 02-25-2016 01:49 PM
Trouble creating multiple VNC virtual displays/session to create multi monitors. fullofentropy Debian 3 10-06-2015 06:58 AM
Multiple VNC client or servers - please help yaximik Linux - Newbie 6 04-14-2012 02:04 AM
Multiple Identity Support Like M$ Outlook Express arun79 Linux - Software 2 05-30-2003 02:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration