Thread: total login time of each user in last

  1. #16
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    FYI, the code you've given simply doesn't work. If you actually have some working code, then run it to check that it works and copy and paste the full code please.

    Anyway, let's focus on the other problem now.
    That's simple. What do you have so far?
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  2. #17
    Registered User
    Join Date
    Aug 2009
    Posts
    39
    Quote Originally Posted by oogabooga View Post
    FYI, the code you've given simply doesn't work. If you actually have some working code, then run it to check that it works and copy and paste the full code please.
    How come? I had run it before and worked fine. How about that?
    Code:
    res="$( last | grep -v "wtmp" )
    users="$( echo $res | awk '{print $1}' | sort -u )"
        for user in $users; do
            totmin=0
            qq=$( echo "$res" | grep "$user" | grep -v "still logged in" | awk '{print $NF}' | sed 's/[()]//g' )
            for q in $qq; do
                min="$( echo $q | awk -F: -v hrs=0 -v min=0     '{hrs=hrs+$1; min=min+$2}END{min=hrs*60+min;print min}' )"
                totmin=$(( $totmin + $min ))
            done
            qq=$( echo "$res" | grep "$user" | grep "still logged in" | awk '{print $(NF-3)}'
            if [ -n qq ]; then
                for q in $qq; do
                    min="$( echo $q | awk -F: -v hrs=0 -v min=0 '{hrs=hrs+$1; min=min+$2}END{min=hrs*60+min;print min}' )"
                    hrs=$( date -u +%H )
                    mins=$( date -u +%M )
                    mins=$(( $(($hrs * 60))  + $mins ))
                    min=$(( $mins - $min ))
                    totmin=$(( $totmin + $min ))
                done
            fi
            echo "$user $totminmins" >> rep1.txt
    Quote Originally Posted by oogabooga View Post
    That's simple. What do you have so far?
    I haven't started at all, because I am stuck.
    Last edited by vril; 04-20-2012 at 05:33 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help with Tracking user login
    By erictu in forum C++ Programming
    Replies: 25
    Last Post: 04-01-2012, 06:57 PM
  2. User login history - bash
    By garcy in forum Linux Programming
    Replies: 3
    Last Post: 05-17-2011, 10:23 AM
  3. Replies: 6
    Last Post: 01-08-2006, 02:49 PM
  4. Replies: 5
    Last Post: 05-06-2004, 09:14 AM
  5. creating a user login system for web pages
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-04-2002, 11:02 PM