LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 09-12-2007, 01:44 PM   #1
yanik
Member
 
Registered: Oct 2003
Location: Montreal Beach
Distribution: Debian Unstable
Posts: 368

Rep: Reputation: 30
Lastlog script help


Hi everyone,

I need a little help here. I was told I need to hand over every login from every users of every nix-like systems.

On linux it was quite easy with the lastlog utility. The output looks like this:

Code:
Username         Port     From             Latest
tien                                       **Never logged in**
msimard                                    **Never logged in**
ydoucet          pts/1    10.5.5.2         Wed Sep 12 14:32:24 -0400 2007
nagios                                     **Never logged in**
nbouchard        pts/0    10.9.5.60        Mon Sep 10 14:09:30 -0400 2007
ftpimg                                     **Never logged in**
apache                                     **Never logged in**
But on Solaris I'm having a hard time. I've found lastx, which give me every last login and it looks like this:

Code:
bash-2.05# lastx -u
Username             Logins  Terminal   Host                 Last Logged in 
etudia10                  3  pts/8      10.9.2.114           Thu Nov 30 16:53:55 2006
etudia08                  3  pts/16     10.9.2.102           Mon Dec 18 14:46:49 2006
scportca                  4  pts/3      10.9.18.55           Wed Sep 12 11:32:24 2007
etudia09                  3  pts/14     10.9.2.104           Thu Nov 30 16:53:29 2006
etudia11                  1  pts/6      10.9.1.71            Thu Nov 30 16:54:17 2006
scolbory                  4  pts/3      10.9.1.60            Wed Jun  7 15:23:51 2006
So far so good, except I don't get those that never logged in. Can someone help me with that? I'm no script guru. I tried something but it doesn't work:

Code:
cat /etc/passwd|cut -d ":" -f1
gives me the login name of all users on the system,
Code:
lastx -u|cut -d " " -f1
gives me the login name of all users that has ever logged in the system.

I tried

Code:
grep -v `lastx -u|cut -d " " -f1` /etc/passwd|cut -d ":" -f1
with no success.

Anyone?

Thank you very much.
 
Old 09-12-2007, 02:49 PM   #2
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
I think a for loop could do you some good. Because `lastx -u|cut -d " " -f1` outputs a list so you need to take one item per time. Maybe something like:
for i in `cat /etc/passwd|cut -d ":" -f1`; do grep $i ...

Maybe this one:
Code:
for i in `cat /etc/passwd|cut -d ":" -f1`;do if (lastx -u|cut -d " " -f1|grep -q $i);then echo $i yes; else echo $i no; fi;echo bla; done
On my system it looks like:
Code:
for i in `cat /etc/passwd|cut -d ":" -f1`;do if (last|cut -d " " -f1|grep -q $i);then echo $i yes; else echo $i no; fi;echo bla; done
root yes
bla
bin no
bla
daemon no
bla
So the yes is the users that have logged in.
A littlebit cleaner to only output a list of non-logged in users:
Note that we invert the if statement here with !
This gives us a list of users that have not logged in:
Code:
for i in `cat /etc/passwd|cut -d ":" -f1`;do if ! (last|cut -d " " -f1|grep -q $i);then echo $i; fi; done
Your version:
Code:
for i in `cat /etc/passwd|cut -d ":" -f1`;do if ! (lastx -u|cut -d " " -f1|grep -q $i);then echo $i; fi; done

Last edited by muha; 09-12-2007 at 03:34 PM.
 
Old 09-12-2007, 03:29 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Since this pertains Solaris I'll move the thread there.
 
Old 09-12-2007, 06:22 PM   #4
yanik
Member
 
Registered: Oct 2003
Location: Montreal Beach
Distribution: Debian Unstable
Posts: 368

Original Poster
Rep: Reputation: 30
hey thanks muha, I'll try that first thing in the morning.
 
Old 09-12-2007, 07:03 PM   #5
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
@muha, its better to break down the code for OP to understand and not cram everything into one line.
@OP. Just an example, adapt to your needs
Code:
last > outlast 
nawk 'BEGIN{FS=":"}
     FNR==NR{user[$1]; next}
     { FS=" " 
       if ( $1 in user ) print $0  
     }
' "/etc/passwd" "outlast"

Last edited by ghostdog74; 09-12-2007 at 07:05 PM.
 
Old 09-13-2007, 07:14 AM   #6
yanik
Member
 
Registered: Oct 2003
Location: Montreal Beach
Distribution: Debian Unstable
Posts: 368

Original Poster
Rep: Reputation: 30
thanks to all,

muha, your last non logged version is what I was looking for, thank you.

Really appreciate.



Yanik
 
Old 09-13-2007, 08:24 AM   #7
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
@ghostdog74: yanik started

@yanik: no problem, cya
 
Old 10-02-2007, 02:39 PM   #8
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
This is a test. Feel free to ignore.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
lastlog - What is it, and how do I rotate it? ifm Linux - Newbie 9 04-22-2011 09:45 AM
lastlog November11 Programming 2 01-10-2007 06:47 PM
lastlog nayabingi Linux - General 2 12-02-2006 03:57 PM
chkrootkit / lastlog Mr. Gone Linux - Security 4 10-13-2005 10:50 AM
another lastlog question ericn Linux - Security 1 12-30-2001 01:34 PM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 05:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration