Jump to content

shell commands to know everything about Virtual Consoles ?


Recommended Posts

I started programming something in bash, that's using consoles a lot.

So far:

- I know how many text consoles were created at boot (grep ... /etc/inittab).

- I know how many X consoles are opened (find /tmp ...).

- I know who is logged (if any) on each text console (who | grep ...).

 

Is there a way to know:

- Who is logged on each X console ?

- What console (its number) is currently on screen ?

- What "root-program" is running on each console (text login, X (display number ? who ?), framebuffer) ?

 

Yves.

Link to comment
Share on other sites

I started programming something in bash, that's using consoles a lot.

So far:

- I know how many text consoles were created at boot (grep ... /etc/inittab).

- I know how many X consoles are opened (find /tmp ...).

- I know who is logged (if any) on each text console (who | grep ...).

 

Is there a way to know:

- Who is logged on each X console ?

- What console (its number) is currently on screen ?

- What "root-program" is running on each console (text login, X (display number ? who ?), framebuffer) ?

 

Yves.

 

the 'w' command doesn't show you most of what you want? probably I'm missunderstanding your question, but anyway, here is an example of output

 

[root@neo tmp]# w

12:22:27 up  9:44,  4 users,  load average: 0,00, 0,02, 0,00

USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT

aru      vc/1      00:39   22:30   0.02s  0.02s -bash

root     vc/2      12:20    1:49   0.02s  0.02s -bash

aru      vc/3      12:21    1:08   0.10s  0.00s /bin/sh /usr/X11R6/bin/startx icewm -- :1

aru      :0         10:46   ?xdm?   1:22   0.45s fluxbox

[root@neo tmp]#

 

Maybe you want a deeper info about what is doing a given user, so probably you can extract almost all the info of each of the proccesses he is running from /proc/#pid/environ for each pid of his jobs.

 

Please, tell me if I'm missunderstanding your question because I find it really interesting.

Link to comment
Share on other sites

Thanks aru. I'll look at this "w" thing. I think you didn't misunderstand. I simply did not know this command (so small it escaped my scrutiny :-)).

 

But I don't intend to spy on the users, so I don't need too much detail.

 

What I want is to offer possibilities like:

1- lock current console

2- lock the whole computer

 

For 1, I need to:

- detect the current console's number,

- detect the console's type

- if it is X, then xscreensaver

- if it is text, then ??? (I don't know how to lock/unlock a text console)

- else nothing (can anything be done...?)

 

For 2, I need to:

- list all the currently opened consoles

- do the same as above (except first step of course) for each console.

 

Yves.

Link to comment
Share on other sites

What I want is to offer possibilities like:

1- lock current console

2- lock the whole computer

 

For 1, I need to:

- detect the current console's number,

Don't know how, but if I've got some time I'll look to it

 

- detect the console's type
Probably if you find the former you'll get this one easily
- if it is X, then xscreensaver

- if it is text, then ??? (I don't know how to lock/unlock a text console)

/usr/bin/vlock

vlock (1) - Virtual Console lock program

 

~$ urpmq -f vlock

vlock-1.3-12mdk.i586

 

For 2, I need to:

- list all the currently opened consoles

- do the same as above (except first step of course) for each console.

'w' would list all opened consoles, but you can lock all of them directly:

 

To lock all the VC do:

~# vlock -a

 

For the X sessions; I guess that I'll do something like:

~# for display in $(ls /tmp/.X*-lock); do

> DISP=":$(echo ${display}|sed "s/.*X([0-9*])-.*/1/")"; 

> xscreensaver-command -lock -display $DISP; 

> done

 

...or w/o using sed:

~# for display in $(ls /tmp/.X*-lock); do

> DISP=":${display##*X}";

> xscreensaver-command -lock -display ${DISP%%-*};

> done;

 

 

HTH

 

PS: If you finally write a script or a couple to handle this I'll be glad to see them, It could be very useful ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...