FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 01-31-2008, 01:05 PM
"Olivier Robert"
 
Default How to tell if someone is connected via vnc

Hi,

I would check for established VNC connections this way:

netstat -tape | grep ESTABLISHED | grep Xvnc

As for warning connected users. If you see there is an established vnc session on port 5902, you could simply do:


export DISPLAY=:2.0; xmessage -center -timeout 60 -file shutdown.txt > /dev/null 2>&1

You could create a list of established connections, translate it to active displays (5902 -> 2.0 | 5903 -> 3.0 ...) and send out a message.


Hope it helps
Olivier

2008/1/31, Henning Larsen <hennlar@start.no>:
Thanks for the answer


I have made a file "ww" that is executable containing:

"netstat -an | grep ESTABLISHED | grep -v 127.0.0.1".

Is this sufficient to tell if any are connected / logged in?

Is there any way to tell people logged in via vnc that I am going to
reboot the system? something like 'wall'?


Henning Larsen

--
fedora-list mailing list
fedora-list@redhat.com

To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list


--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 01-31-2008, 01:52 PM
Henning Larsen
 
Default How to tell if someone is connected via vnc

Thanks for the good answer.

On Thu, 2008-01-31 at 15:05 +0100, Olivier Robert wrote:
> Hi,
>
> I would check for established VNC connections this way:
>
> netstat -tape | grep ESTABLISHED | grep Xvnc
>
> As for warning connected users. If you see there is an established vnc
> session on port 5902, you could simply do:
>
> export DISPLAY=:2.0; xmessage -center -timeout 60 -file shutdown.txt
> > /dev/null 2>&1

How can I determine what the user responds, is there errorlevels or
anything like that? Hundred years ago I was making a lot of advanced
BAT-files in msdos, but have not done much of those things in Linux yet.
I could or maybe should find out reading man-pages, but have already
asked.

What is the reason for doing ' > /dev/null 2>&1'

> You could create a list of established connections, translate it to
> active displays (5902 -> 2.0 | 5903 -> 3.0 ...) and send out a
> message.
>
> Hope it helps
> Olivier
>
It helps a lot, Thanks

Henning Larsen



--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 01-31-2008, 06:12 PM
"Olivier Robert"
 
Default How to tell if someone is connected via vnc

Hi,

1. "How can I determine what the user responds, is there errorlevels or anything like that?"

You can check for the exit status of the xmessage command

2. "What is the reason for doing ' > /dev/null 2>&1'"


It redirects any standard out and standard error to oblivion

Let's say you have a vnc session on port 5902. You want a script that checks if there's a session and display a message to the user. And you want to know if the user read the message. Here's what you could do. (you'll have to adapt and add a loop in there if you have several vnc sessions)


Edit the linux user's ~/.vnc/xstartup and add an "xhost +" in it. Otherwise you will not be able to display the message.

Use a script similar to this one: (of course, you will adapt and enhance)


#!/usr/bin/env bash

netstat -tape | grep ESTABLISHED | grep Xvnc | awk '{print $4}' | awk -F ":" '{print $2}' > log-ports

for user in `cat log-ports`
do
******* case $user in

*************** 5902)
*********************** export DISPLAY=:2.0; xmessage -buttons "I understand":10 -center -timeout 60 -file testmsg > /dev/null 2>&1
*********************** [ $? -eq 10 ]

*************************** && echo "$user acknowledged!"
*************************** || echo "No answer from $user!"
*********************** ;;
******* esac

done

The user connected to 5902 will get a windowed message with a "I understand" button. If he clicks on it, you'll know. If he doesn't, it'll time out after 60 seconds and return an exit status of 0 (zero): you'll know too .


Hope it helps,
Olivier


2008/1/31, Henning Larsen <hennlar@start.no>:
Thanks for the good answer.

On Thu, 2008-01-31 at 15:05 +0100, Olivier Robert wrote:
> Hi,
>
> I would check for established VNC connections this way:
>
> netstat -tape | grep ESTABLISHED | grep Xvnc

>
> As for warning connected users. If you see there is an established vnc
> session on port 5902, you could simply do:
>
> export DISPLAY=:2.0; xmessage -center -timeout 60 -file shutdown.txt

> > /dev/null 2>&1

How can I determine what the user responds, is there errorlevels or
anything like that? Hundred years ago I was making a lot of advanced
BAT-files in msdos, but have not done much of those things in Linux yet.

I could or maybe should find out reading man-pages, but have already
asked.

What is the reason for doing ' > /dev/null 2>&1'

> You could create a list of established connections, translate it to

> active displays (5902 -> 2.0 | 5903 -> 3.0 ...) and send out a
> message.
>
> Hope it helps
> Olivier
>
It helps a lot, Thanks

Henning Larsen



--
fedora-list mailing list

fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list



--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 
Old 01-31-2008, 07:07 PM
Henning Larsen
 
Default How to tell if someone is connected via vnc

Thank you Olivier

On Thu, 2008-01-31 at 20:12 +0100, Olivier Robert wrote:
> Hi,
>
> 1. "How can I determine what the user responds, is there errorlevels
> or anything like that?"
>
> You can check for the exit status of the xmessage command
>
> 2. "What is the reason for doing ' > /dev/null 2>&1'"
>
> It redirects any standard out and standard error to oblivion
>
> Let's say you have a vnc session on port 5902. You want a script that
> checks if there's a session and display a message to the user. And you
> want to know if the user read the message. Here's what you could do.
> (you'll have to adapt and add a loop in there if you have several vnc
> sessions)
>
> Edit the linux user's ~/.vnc/xstartup and add an "xhost +" in it.
> Otherwise you will not be able to display the message.
>
> Use a script similar to this one: (of course, you will adapt and
> enhance)
>
> #!/usr/bin/env bash
>
> netstat -tape | grep ESTABLISHED | grep Xvnc | awk '{print $4}' | awk
> -F ":" '{print $2}' > log-ports
>
> for user in `cat log-ports`
> do
> case $user in
> 5902)
> export DISPLAY=:2.0; xmessage -buttons "I
> understand":10 -center -timeout 60 -file testmsg > /dev/null 2>&1
> [ $? -eq 10 ]
> && echo "$user acknowledged!"
> || echo "No answer from $user!"
> ;;
> esac
>
> done
>
> The user connected to 5902 will get a windowed message with a "I
> understand" button. If he clicks on it, you'll know. If he doesn't,
> it'll time out after 60 seconds and return an exit status of 0 (zero):
> you'll know too .
>
> Hope it helps,
> Olivier
>

Thank you very much, I learned so much from your answer so that I will
be busy programming scripts for a long time.

Henning Larsen



--
fedora-list mailing list
fedora-list@redhat.com
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
 

Thread Tools




All times are GMT. The time now is 07:22 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org