Operating System - Linux
1745786 Members
3828 Online
108722 Solutions
New Discussion юеВ

Re: Show logins on Red Hat Linux

 
Ejnar Svejstrup_1
Occasional Advisor

Show logins on Red Hat Linux

Hi,
On HP/UX we have the command "logins" which shows the user logins on the system. Does anybody know a similar command for Red Har Linux.

Thanks...
10 REPLIES 10
Ralph Grothe
Honored Contributor

Re: Show logins on Red Hat Linux

Hi Ejnar,

we run several Linux boxes with RHEL3.

To my knowing a logins command or act-alike doesn't come with the standard distros.

I guess you could obtain sources from logins
(maybe GNU or similar) and try to build it on RH.

However the functionality logins offers can easily be scripted by parsing /etc/passwd
(shell, awk, perl, python, or C getpw* syscalls).
Mostly a mere shell alias will suffice.

So I think it isn't really necessary to have a logins implementation for Linux.
Madness, thy name is system administration
Muthukumar_5
Honored Contributor

Re: Show logins on Red Hat Linux

Try this.

// logins.c
#include
#include
#include

main()
{
struct passwd *pwd;
pwd=getpwent();
while (pwd != NULL )
{
printf ("%-15s %-6d %-15s %-6d %s\n",pwd->pw_name,pwd->pw_uid,pwd->pw_name,pwd->pw_gid,pwd->pw_gecos);
pwd=getpwent();
}

endpwent();
}

# make logins
# ./logins

hth.

Easy to suggest when don't know about the problem!
RAC_1
Honored Contributor

Re: Show logins on Red Hat Linux

Slow login may also be related to host name resolution.

telnet ip_address
telnet host_name

Which one is slow, if second then it may be the way host name resolution is configured. If first, you need to explore more to know the problem of it.
There is no substitute to HARDWORK
Ivan Ferreira
Honored Contributor

Re: Show logins on Red Hat Linux

If the "logins" command shows a list of users on the system, you can use:

awk -F ":" '{ print $1 }'

If you do not use local authentication:

getent passwd |awk -F ":" '{ print $1 }'
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Rick Garland
Honored Contributor

Re: Show logins on Red Hat Linux

Here is an example of using 'awk' to parse through the passwd file.

This example will list the UIDs in use and will present the information so you can see if duplicate UIDs are in use.


Steven E. Protter
Exalted Contributor

Re: Show logins on Red Hat Linux

Just ran a test. The standard user report passwd -sa does not work on Linux.

awk script will have to be used.

or.

last | sort -u | more

That will provide you a list of accounts that were actually used.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dave Falloon
Trusted Contributor

Re: Show logins on Red Hat Linux

I'm not familiar with the HP logins command but if you want to see a list of the last time anyone has logged in use:

lastlog

Or for currently logged in users:

who

If you want to see a password file style list of all users that can log into a system run:

getent passwd

--Dave
Clothes make the man, Naked people have little to no effect on society
Raj D.
Honored Contributor

Re: Show logins on Red Hat Linux

Hi Ejnar ,

Here it is :

# sort -t: -k 3n,3 passwd | awk -F ":" '{printf ("%-20s %7s %7s %s\n", $1,$3,$4,$5)}'


Enjoy , Have fun,
Cheers ,
Raj.



" If u think u can , If u think u cannot , - You are always Right . "
Jeff Hoevenaar
Frequent Advisor

Re: Show logins on Red Hat Linux

how about:

who -u

OR

finger