LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to get all login names though they are logged ?? (https://www.linuxquestions.org/questions/linux-general-1/how-to-get-all-login-names-though-they-are-logged-216162/)

dileepkk 08-11-2004 07:24 AM

How to get all login names though they are not logged ??
 
Hi

I am searching for a system call that provides all login names.
I know that they will be in /etc/passwd.


Thanks in advance

Dileep :Pengy:

Disillusionist 08-11-2004 01:21 PM

I don't think there is a system call to show all valid user accounts.

You could try:

cat /etc/passwd|awk -F: '{ printf($1); }'

But this will just get the username from /etc/passwd for all entries, and as a lot of these are system accounts that are not allowed to login... it probably is not what you are after.

What is it you are trying to acheive?

If you want to know who is currently logged in you can use either finger or who

dileepkk 08-12-2004 01:30 AM

I want to get all user login names and other details evn if they are not login
 
Hi,

cat /etc/passwd|awk -F: '{ printf($1); }'
prints all the entries,
But i want only valid login names. how to get them.

if we r using "redhat-config-users" we will get the details,
actuallu i want those details, for that only iam searching the system call.


Thankd in advance

Dileep

masand 08-12-2004 01:40 AM

try your hand at
'wtmp' and 'utmp' files

man utmp,man wtmp

regards

Disillusionist 08-12-2004 11:49 AM

Ok, various options

1. Assuming valid users home directories reside directly under /home the most basic option is:

ls /home

2. If you want General Users, assuming that general users have a UID between 101 and 65533

cat /etc/passwd|awk -F: '\
{
if ( $3 > 100 ) {
if ( $3 < 65534 ) {
printf($1"\n");
}
}
}'

3. If you want All User accounts that can log in, note that neither option 1 or 2 will guarantee this.
** You will need to run this as root (or sudo) **

cat /etc/shadow|awk -F: '\
{
if ( $2 != "!" ) {
if ($2 != "*" ) {
printf($1"\n");
}
}
}'

This list will include the root account


All times are GMT -5. The time now is 09:55 PM.