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 Code:
bash-2.05# lastx -u Code:
cat /etc/passwd|cut -d ":" -f1 Code:
lastx -u|cut -d " " -f1 I tried Code:
grep -v `lastx -u|cut -d " " -f1` /etc/passwd|cut -d ":" -f1 Anyone? Thank you very much. |
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 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 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 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 |
Since this pertains Solaris I'll move the thread there.
|
hey thanks muha, I'll try that first thing in the morning.
|
@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 |
thanks to all,
muha, your last non logged version is what I was looking for, thank you. Really appreciate. Yanik |
@ghostdog74: yanik started :D
@yanik: no problem, cya :) |
This is a test. Feel free to ignore.
|
All times are GMT -5. The time now is 03:22 PM. |