Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2008
    Posts
    2

    Unanswered: Last Login date for users

    I've written a simple ksh script to list the last login for all the users on my systems. The problem is that it uses the last command and if the user hasn't logged in since the wtmp file was created I only get the following from last:
    .
    wtmp begins Feb 23 11:40
    .
    My script looks like this

    #!/bin/ksh

    for i in `lsuser -a ALL`
    do
    echo `last -1 $i` >> /tmp/lastloginnew.txt
    done


    I also found the following script here, on this forum, but it was from 2005 so I decided that it wasn't probably being monitored.

    #!/bin/ksh

    UIDS=`last | cut -f1 -d' ' | cat -n | sort -k 2.1 | uniq -f1 | sort
    -n | cut -f2`

    for UID in $UIDS
    do
    last -1 $UID
    done

    Both of these give me the same thing, just that the first redirects the output to a file that I can e-mail to other team members.

    What I'm looking for is some way for the script to print the user name prior to running the last command so that each line will give me the user name the last command is running for. Any help would be greatly appreciated.

    -Chas

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    like this?
    echo "$uid: `last -1 $uid | sed '/^$/d'`"

  3. #3
    Join Date
    Jan 2008
    Posts
    2
    Thanks so much. I'll let you know how it goes.

    -Chas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •