Find the answer to your Linux question:
Results 1 to 2 of 2
I need some help. I want to create a script to tell me info about all users from a system who logged in in the last month, at least 3 ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    1

    Bash scripting

    I need some help. I want to create a script to tell me info about all users from a system who logged in in the last month, at least 3 times. I made this over far but I need for all users... To get all users from /etc/passwd not to type them from keyboard... Can someone help me ?Thanks.





    if [ $# = 0 ]
    then
    echo "Enter user: "
    else
    for i
    do
    last -3 $i || echo "The user $i never logged in!"
    done
    fi

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    awk 'BEGIN{FS=":"}
    {
     cmd="last -3 " $1
     while( (cmd | getline result )>0 ) {
       if ( result ~ $1 ) {
        print result
       }
     }
     close(cmd)
    }' /etc/passwd

Posting Permissions

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