You are not logged in.

#1 2010-08-28 16:00:12

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Get the list of logged users (w does not work)

Hi,

I use netcfg and am writing a script I want to run every time the network is up (POST_UP thing in netcfg). The thing is I need the list of logged in users at that time.
I thought `w` and some string processing would do the trick but here is what I get:

$ w
 17:55:07 up  1:51,  0 users,  load average: 0.00, 0.03, 0.07
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT

I cross checked with `who` and what not but it seems that nobody is ever logged in (although I am at the moment I am running `w`).
Why does `w` behave in this way ? How to fix this ? How to get what I want (the list of users currently logged in) ?

Thank you in advance for your help !

yms

PS I use Arch with dwm and I am logged in automatically at bootup (then xscreensaver locks the session). Tell me if you need some more information.


Sorry for any English mistakes, I am not a native speaker.

Offline

#2 2010-08-28 16:35:15

Wintervenom
Member
Registered: 2008-08-20
Posts: 1,011

Re: Get the list of logged users (w does not work)

Perhaps $(users) is what you want?

Last edited by Wintervenom (2010-08-28 16:36:31)

Offline

#3 2010-08-28 16:45:11

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Get the list of logged users (w does not work)

yms wrote:

I use Arch with dwm and I am logged in automatically at bootup

So do I:

[karol@black extra]$ w
 18:49:12 up  7:24,  1 user,  load average: 0,00, 0,00, 0,01
USER     TTY        LOGIN@   IDLE   JCPU   PCPU WHAT
karol    tty1      11:27    7:21m  3:36   0.01s /bin/sh /usr/bin/startx

Offline

#4 2010-08-28 17:34:21

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: Get the list of logged users (w does not work)

Thank you for your answers but:

@Wintervenom: users is empty ... which is (unfortunately) consistent with w not showing anything ...
@karol: That's weird ... maybe we're not logged in in the same way. How do you proceed ?


Sorry for any English mistakes, I am not a native speaker.

Offline

#5 2010-08-28 17:37:38

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Get the list of logged users (w does not work)

I have

c1:2345:respawn:/sbin/mingetty --autologin karol tty1 linux
#c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux

in my /etc/inittab.

I log into X manually via 'startx'.

Last edited by karol (2010-08-28 17:38:25)

Offline

#6 2010-08-29 16:19:21

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: Get the list of logged users (w does not work)

In my /etc/inittab i have:

c1:2345:respawn:/sbin/agetty -8 38400 tty1 linux

# ... other default stuff

x:5:once:/bin/su yms -l -c "/bin/bash --login -c startx >/dev/null 2>&1"

so I don't have to run startx myself. Maybe my thing is all wrong and just happens to work for logging in but creates the other(s) problems.

Any ideas ?


Sorry for any English mistakes, I am not a native speaker.

Offline

#7 2010-08-29 16:46:30

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Get the list of logged users (w does not work)

Offline

#8 2010-08-29 18:15:22

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: Get the list of logged users (w does not work)

The thing is, I don't use bash anymore (I switched to zsh) and I am trying to get rid of it wherever it is possible. I'll first try your way of autologin and run xorg manually to see if it changes anything as far as the original problem concerned.

I still would like to know what is going on and why my setup does not work the way it is :-/


Sorry for any English mistakes, I am not a native speaker.

Offline

#9 2010-08-29 18:18:52

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Get the list of logged users (w does not work)

yms wrote:

The thing is, I don't use bash anymore (I switched to zsh) and I am trying to get rid of it wherever it is possible. I'll first try your way of autologin and run xorg manually to see if it changes anything as far as the original problem concerned.

I still would like to know what is going on and why my setup does not work the way it is :-/

How about putting it in .zshrc or whatever you have there? Maybe you need to fix some syntax issues but it should work.

Edit: I've just run

/bin/su karol -l -c "/bin/bash --login -c startx >/dev/null 2>&1"

and 'w' showed me logged on.

Last edited by karol (2010-08-29 18:27:02)

Offline

#10 2010-08-30 20:43:57

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: Get the list of logged users (w does not work)

Hi,

I ran some tests and I found out that there are some flaws with all autologin techniques I tried.

1) What I have been using up to now:

x:5:once:/bin/su yms -l -c "/bin/bash --login -c startx >/dev/null 2>&1"

I (yms) do not show up in w, who, users etc.

2) Using mingetty like karol to autologin.

c1:2345:respawn:/sbin/mingetty --autologin yms tty1 linux

I am logged in correctly but I need to start Xorg myself or using a very hackish solution.

I am used to ugly hacks and sometimes they are a necessary evil but the problem is here that whenever my computer is locked (with xscreensaver) one can always switch to tty1 (Ctrl+Alt+F1), kill or pause startx and thus have access to a prompt ... This makes the whole locking thing ... useless.

Oh and if you run:

$ startx ; logout

so that if you kill startx then you are logged out and thus not getting access to a prompt, you'd be surprised because mingetty logs you back in immediately ;-)

@karol: I think you might have the same problem with your setup.

3) Using both the mingetty login and

x:5:once:/bin/su yms -l -c "/bin/bash --login -c startx >/dev/null 2>&1"

With this, you are logged in twice (and only appearing once in w, who, users etc which is still problematic (you should be appearing twice) ... Moreover, you have the same problem as in 2).

I really need a(n elegant) solution to this. Any ideas ?


Sorry for any English mistakes, I am not a native speaker.

Offline

#11 2010-09-01 14:08:18

yms
Member
From: Switzerland
Registered: 2009-06-05
Posts: 64

Re: Get the list of logged users (w does not work)

I really need help on this one :-/ Anybody has an idea ?


Sorry for any English mistakes, I am not a native speaker.

Offline

#12 2010-09-04 18:50:56

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Get the list of logged users (w does not work)

I've already run out of ideas, but I run into a couple things that may confuse you, so I decided to post them here ;P

http://bugs.archlinux.org/task/15217#comment47079

phrakture wrote:

Do me a favor: Run "bash -l" and then check lastlog. Random guess is that you may not be using a login shell

You log in with bash and use zsh for the rest of the day but I log in with dash and bash still shows '1 user'.


Slim issues:
https://bbs.archlinux.org/viewtopic.php?pid=672284
https://bbs.archlinux.org/viewtopic.php … 10#p335110


I'm not sure if any of this is of use.



Let's see where we are:
1. You want to fix '0 users' issue.
2. You want to log in into X automatically.
and
3. You want to lock your screen with xscreensaver.

While mingetty helps with the first, it somewhat complicates the second and breaks the third.
Have you looked into other tools like slock to securely lock your computer?

Last edited by karol (2010-09-04 19:14:50)

Offline

Board footer

Powered by FluxBB