Sponsored Content
Top Forums Shell Programming and Scripting Script to list users and their last login? Post 302458570 by Franklin52 on Friday 1st of October 2010 06:23:52 AM
Old 10-01-2010
Quote:
Originally Posted by tanngo
hi all,I'm trying to write a script to create a file with a list of all users, their gid, gecos field and their last login time e.g.user1 22 Fred Bloggs Sep 20fairly new to scripting, this is what I've got so far#!/bin/sh( userlist= cat /etc/passwd | awk -F: '{print $1," ",$4," ",$5}' for name in $userlist do login= last -1 $name echo $name $login >> `hostname`_userlogins.txt done)The output of the first part is fine but I can't get the loop and last command working, and need to append the output of 'last -1' for each user to the end of their 'line'Any help would be greatly appreciated!
Moderator's Comments:
Mod Comment This is almost unreadable, please edit the post, indent the code and use code tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

users login

Hello everyone I need to send to a file the last command from all users who log in and log out by week or month. My questions are I can do it with the command or I need to do a script ? If the answer is I need to do a script, someone can help me because Im complete new to make a... (3 Replies)
Discussion started by: lo-lp-kl
3 Replies

2. Programming

how can get users list and their login time?

i'm sorry if yesterday i posted this thread in unix for dummies forums, :D i am a newbie in C programming i want to get active users list and their login time... i have search and learn about passwd and utmp, but i only can get user list without their login time... do you have an idea... (2 Replies)
Discussion started by: alif
2 Replies

3. UNIX for Dummies Questions & Answers

How to do a login time and date list of users never logged on?

Hello, I'm trying to do a list of user that never connected to a couple of servers. I want to do a diff between the servers lists, and print out only the users that never has logged on each server. Here my first step : SERVER01: # finger `egrep -v -e "^\s*#" /etc/passwd | awk '{ print $1 }' |... (4 Replies)
Discussion started by: gogol_bordello
4 Replies

4. HP-UX

No users can login

Dear Forum, I had this case before, all of sudden all users including root can't login. What done is by connecting to console port and resetting root password, "pwunconv" command, reboot server. My question is, how this can happen??? thanks :confused: (3 Replies)
Discussion started by: irda
3 Replies

5. Shell Programming and Scripting

FTP script to login and list files to log file

Hi Guys I did a forum search for "ftp scripts" Looked at 8 pages and didnt see anything that would help. Most seem to be logging into a ftp server and transfering files. What I need to do is login to a FTP server. Goto a folder and list it so it showes newest files first. It would be nice to... (4 Replies)
Discussion started by: voorhees1979
4 Replies

6. Shell Programming and Scripting

Script to list primary group of users

Dear All I am facing a problem with my script. I have to found the primary group of users . So first I selected all the groups and users register from a specific user : ONE Then I am making a file with all groups attached to the user : ONE Then I am making a file with all... (8 Replies)
Discussion started by: Aswex
8 Replies

7. UNIX for Advanced & Expert Users

Need A Script To List All Failed Log In Users

I need to list all the failed log in users as part of audit report. How can I do so in Linux to find all the audit log records and then upload to a table for future reference. I am using oracle 10g on Linux. Hope I will get a quick response from the experts. Thanks in advance for the tips. (3 Replies)
Discussion started by: oraQ
3 Replies

8. Shell Programming and Scripting

script to ignore the user from list of users

Hi, I have a situation where I want to ignore few users from list of users and print rest of user in log file. say, I want to ignore aaa, bbb, ccc, ddd .. ppp from list of 20 user (do not want to include) What is the good command or any script? Thanks in advance. (1 Reply)
Discussion started by: sumit30
1 Replies

9. Shell Programming and Scripting

help to create script for added date to list users

hi my friends im asking for the possibility to creat a script in ubuntu for added date to list users for doing this : - search in debug connected user of all connected users - if a new user is connect for the first time to my server the script record the date of the connection and added it... (1 Reply)
Discussion started by: amzioujda
1 Replies

10. Shell Programming and Scripting

Get Home Directory for Users in Login Hook Script

I'm writing a script to use as a LoginHook for my Mac users. As part of this script, I need to write to a location in their home directory, but I can't seem to access the path - at this point in the login process, $HOME is empty and ~ gives the path to root's home. Unfortunately, I can't just do... (1 Reply)
Discussion started by: blondepianist
1 Replies
USERLIST(8)						      Finger-type Userlisting						       USERLIST(8)

NAME
userlist - Userlisting of who's on your system. SYNOPSIS
userlist DESCRIPTION
This program simply gives you a listing of who is connected to your system. It is used primarily in the sorted listing of cfingerd, which utilitizes the same method of display for a more uniform output between systems. (It also made more sense to do it this way instead of having jumbled up display listings in sorted finger displays. Besides, it made more sense to do this than use finger. :) This program functions with the same types of things in mind that cfingerd does. If the user has a .nofinger file, their username will not be displayed in the userlisting. Example output is shown as: Username Real Name Idletime TTY Remote console username I'm real ... 9d 23:59 0 (remote.site.com) where it would display the user's login name, the user's real name, their idle time given in the format "dd hh:mm", their TTY, and their remote location (or where they're telnetting from). If the username is over 8 characters, the program will not search for their information in the passwd file, since it may be too long. Besides, it checks getpwnam, anyway. :) OPTIONS
-c Give standard CFINGERD (custom) output. -n List only people idle less than one day. ADDITIONAL
Although userlist is not required to run as suid root, it is a good idea. The reason is it checks each users' directory for a .nofinger file. If indeed that user has a .nofinger file in his/her directory, that user will not be shown in the userlisting. If you change the program to run as nobody.nobody, you are free to do so. But you will also show the users if they are online, regardless of whether or not they have a ".nofinger" file (as long as their directory is NOT world-readable.) CONTACTING
If you like this program, have any suggestions on how it could be modified, or have bug reports, please write to: khollis@bitgate.com. Your continued Public Domain support is appreciated! Thanks. SEE ALSO
cfingerd.conf(5), cfingerd(8), finger(1). cfingerd 1.4.2 29 August 1999 USERLIST(8)
All times are GMT -4. The time now is 01:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy