Find the answer to your Linux question:
Results 1 to 3 of 3
Hi! I'm new in scripting and I need some help with one simple script. I have to write a program that shows in a predetermined period (using "last" command), to ...
  1. #1
    Just Joined!
    Join Date
    Oct 2009
    Posts
    3

    bash script for showing last users

    Hi! I'm new in scripting and I need some help with one simple script. I have to write a program that shows in a predetermined period (using "last" command), to draw up a list of users who have used the machine during this period. Each user to indicate how many sessions it has been during this period. Output must be sorted alphabetically by usernames (increasing alphabetically). Can someone help

  2. #2
    Just Joined!
    Join Date
    Oct 2009
    Posts
    3

    last users

    The code should be something like:
    cat lastfile | cut -c1-8 | egrep -v '(^reboot)|(^$)|(^wtmp a)|(^ftp)' | sort | uniq -c | sort -rn

    But how to I predetermine the period and sort alphabetically(increasing)?

  3. #3
    Just Joined!
    Join Date
    Oct 2009
    Posts
    3

    Re:

    I understand that id I want to sort by user name then
    Code:
    sort -k 2
    number means the field to sort. So now I have only some code but still nos script:
    Code:
    cat lastfile | cut -c1-8 | egrep -v '(^reboot)|(^$)|(^wtmp a)|(^ftp)' | sort | uniq -c | sort -k 2
    Script should show something like this:
    Code:
    Example:\\>users.sh  Oct 26 11:00 - Oct 27 14.00
     SESSIONS      USER              LAST LOGIN
       12              userA      Tue Oct 27 13:45 - 13:50  (00:04)
        3               userB      Tue Oct 27 13:31   still logged in
        5               userC      Tue Oct 27 13:31   still logged in
       ...              .......        ............................................

Posting Permissions

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