Sponsored Content
Top Forums Shell Programming and Scripting bash script for showing last users Post 302365597 by methyl on Tuesday 27th of October 2009 01:50:32 PM
Old 10-27-2009
It is probably easier to work with the raw wtmp file than with "last" if only because "last" is always in reverse chronological order.
I'm assuming that you want to do this in shell rather than a "C".

The fact that you can process an entire "output from "last" suggests that you properly maintain your wtmp file(s) to a manageable size.

Tip: process the wtmp file with program "fwtmp" and you will have all the raw material in chronological order in a format suitable for splitting into fields with "cut". Each record includes the date since the epoch as well as in character format. Each record contains a code as to the type of record. Beware that some records don't have a username because "wtmp" records that fact that someone is running a login process (hence the reason to use "cut").

There are many possible ways to deal with the timespan. You could run "fwtmp" at the start of the period and again at the end of the period. Count the records in each file and you then know how many have changed. Use "sed" not "tail" to get the records you require. At this point you could convert the selected records back to wtmp format in a file with a new name and run "last" on that file.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash/awk scripting help (creating OLD new users)

I need some help making this script... I guess I'm having trouble even interpretating what to even get started on... I need to create a script that will search a given directory (typically a user's home directory, but not necessarily) as provided on the command line and any sub-directors for... (2 Replies)
Discussion started by: Jukai
2 Replies

2. Shell Programming and Scripting

Showing offline users

Hi, Is there any command for showing offline users? The only way I can think of doing it (as i cant find a command) is getting a list of all the online users, and comparing it to /etc/passwd, anything that is in /etc/passwd and not in the users file will be offline users. But I have no... (4 Replies)
Discussion started by: mikejreading
4 Replies

3. Shell Programming and Scripting

Bash Help: users who are not logged into the system to display

A Newbie here, I am working on a script and am having problems with the else part of the script. I can't get the users who are not logged into the system to display on the screen with their username and the text "The user is not logged in". I am sure it is something simple and stupid, but I... (5 Replies)
Discussion started by: rchirico
5 Replies

4. UNIX for Dummies Questions & Answers

Need help showing which network protocol users use.

I'm having a bit of a trouble trying to figure out how to tell which network protocol users HAVE been logging in with. I know how to find this information for currently logged in users : maximillian.gardner@syccuxfs01:~> who joseph.blosser pts/0 2012-01-15 14:07 (198.107.160.185)... (5 Replies)
Discussion started by: maximillian.g
5 Replies

5. Red Hat

Showing all users in 'users' and 'top' commands

Hi All, I work in a multi user environment where my school uses Red Hat Linux server. When I issue commands such as "top" or "users", I get to see what others are doing and what kinds of applications they are running (even ps -aux will give such information). "users" will let me know who else is... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

6. Shell Programming and Scripting

Script in bash wchich creating a new users...

Hi, I am a new on this forum but i like :) I need a script in bash which will be crating a new user with folder for websites. For example: I will run this program and he creating a new user(with my name) and folder whcich name like user and if i will localho/~user in browser, she show me files from... (1 Reply)
Discussion started by: puclavv
1 Replies

7. UNIX for Dummies Questions & Answers

About adding users from a text file using bash

hello, I try to add users from a text file with this form: username:groupename:homedir first i extract data which is separated by ":" then i use useradd to add users/groups. but,,, my code doesn't works : #!/bin/bash echo "give me a text file: " read dir # control if... (2 Replies)
Discussion started by: ref012
2 Replies

8. Ubuntu

Expect /bash, 2 ssh login users

HI all i need to connect to about 900 cisco routers and switch to do some configs changes. the issue i am having is that half the devices have one set of username and password and the other half have another username and password. From expect or bash script i can ssh into a device and make... (1 Reply)
Discussion started by: quintin
1 Replies

9. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies
LAST(1) 						      General Commands Manual							   LAST(1)

NAME
last - indicate last logins of users and teletypes SYNOPSIS
last [ -f filename ] [ -N ] [ name ... ] [ tty ... ] DESCRIPTION
Last will look back in the wtmp file which records all logins and logouts for information about a user, a teletype or any group of users and teletypes. Arguments specify names of users or teletypes of interest. Names of teletypes may be given fully or abbreviated. For example `last 0' is the same as `last tty0'. If multiple arguments are given, the information which applies to any of the arguments is printed. For example `last root console' would list all of "root's" sessions as well as all sessions on the console terminal. Last will print the sessions of the specified users and teletypes, most recent first, indicating the times at which the session began, the duration of the session, and the teletype which the session took place on. If the session is still continuing or was cut short by a reboot, last so indicates. The pseudo-user reboot logs in at reboots of the system, thus last reboot will give an indication of mean time between reboot. Last with no arguments prints a record of all logins and logouts, in reverse order. The -f filename option allows the user to examine an alternate wtmp file. The -N option limits the report to N lines. If last is interrupted, it indicates how far the search has progressed in wtmp. If interrupted with a quit signal (generated by a con- trol-) last indicates how far the search has progressed so far, and the search continues. FILES
/usr/adm/wtmp login data base /usr/adm/shutdownlog which records shutdowns and reasons for same SEE ALSO
wtmp(5), ac(8), lastcomm(1) AUTHOR
Howard Katseff 4th Berkeley Distribution April 29, 1985 LAST(1)
All times are GMT -4. The time now is 12:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy