User login history - bash

This is a discussion on User login history - bash within the Linux Programming forums, part of the Platform Specific Boards category; Hello everyone, I need to make a bash program that will print the number of times and how much time ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    2

    User login history - bash

    Hello everyone,

    I need to make a bash program that will print the number of times and how much time users have been logged in during a certain time period(two dates given by command line agruments - ./login.sh 27/04 06/05).

    The result must look something like this:

    username | no. of times this user has been loged in | how much time this user has been logged in(days hours:minutes)

    example:

    johnk 2x 0 days 2:46
    deanb 4x 0 days 11:42
    lukas 2x 0 days 1:58
    peterp 3x 1 days 18:41

    Any help would be appreciated. Thank you

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    This sounds like homework. Have you made an attempt? Please post some code to show that you have.
    I'll give you the benefit of the doubt and give you a hint. All the information you need should be in a log file in /var/log/ - Sometimes it will be in security.log or auth.log depends on the distribution. All you need to do is extract it and format it.
    Last edited by sand_man; 05-16-2011 at 06:14 PM.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    2
    Quote Originally Posted by sand_man View Post
    This sounds like homework. Have you made an attempt? Please post some code to show that you have.
    I'll give you the benefit of the doubt and give you a hint. All the information you need should be in a log file in /var/log/ - Sometimes it will be in security.log or auth.log depends on the distribution. All you need to do is extract it and format it.
    Hi, thank you for your answer. No, it's not homework. It's just an excercise for myself that I would like to complete. I have already used the 'last' command which extracts info from the var/log/wtmp file. The only problem is that I don't know how to format the text correctly. I should probably save the text returned by the last command into a file or variable but I don't know how to begin. If you could give me any hints I would really appreciate it.

    Thank you

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by garcy View Post
    The only problem is that I don't know how to format the text correctly. I should probably save the text returned by the last command into a file or variable but I don't know how to begin. If you could give me any hints I would really appreciate it.
    Sounds like you are beginning at the beginning; this is probably a decent exercise. If you are working in C, you could either read var/log/wtmp yourself or use popen() to get the output of the "last" command.

    Pipe to a Subprocess - The GNU C Library

    See what you can come up with and then post your attempt in the programming forum, someone will help.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-08-2009, 11:55 AM
  2. Can't run Bash!
    By Yarin in forum Tech Board
    Replies: 3
    Last Post: 05-11-2009, 07:25 PM
  3. bash completion on user input
    By t0bias in forum Linux Programming
    Replies: 6
    Last Post: 12-20-2007, 10:43 AM
  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21