Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have one system that I would like to do a little clean up, so I would like to get all user accounts and last date they accessed they mail. It is a Debian system.

So far I got to this:

cut -d: -f1 /etc/passwd | xargs -n1 finger | grep "Mail last read" 

But I dont know how to write that username in front of Mail last read Sun Aug 12 03:06 2012 (CEST)

Thank you

share|improve this question
    
also asked on stackoverflow: stackoverflow.com/q/12006714/7552 –  glenn jackman Aug 18 '12 at 1:31

2 Answers 2

up vote 2 down vote accepted

You can try something like:

for USER in $(cut -d: -f1 /etc/passwd); do MAILINFO=$(finger $USER | grep "Mail last read"); echo "$USER - $MAILINFO"; done

I think you should get the gist ... you need to manipulate the return from the grep "Mail last read" a bit.

share|improve this answer
    
Thank you, it works :) –  user899119 Aug 17 '12 at 13:47
cut -d: -f1 /etc/passwd |
xargs finger |
awk  '/^Login:/ { user = $2 }
      /^Mail last read/ {print user, $0}'

Or alternatively

ls -ltu /var/spool/mail

(or /var/mail or wherever the mail is located on your system).

share|improve this answer
    
ls -ltu /var/spool/mail will show the last time they received mail, not the last time it was read. –  bahamat Aug 17 '12 at 23:55
    
@bahamat -u shows the atime. That's what finger looks at anyway. –  Gilles Aug 18 '12 at 0:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.