- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- last login script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2001 04:47 AM
05-09-2001 04:47 AM
awk -F: '{print "last | grep "$1" | head -1"}' /etc/passwd|ksh - > /home1/nickd/lastlogin
The missing piece is to sort the output file so that the file is sorted from newest to oldest.
Can anyone suggest how I might be able to do that?
All help is appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2001 05:15 AM
05-09-2001 05:15 AM
Re: last login script help
A while back I wrote a script for someone that did this, taking care of sorting dates from 'last'. I've attached it here. Run it with '-v' if you want verbose output. Without that option, you get a summary of login per user.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2001 05:16 AM
05-09-2001 05:16 AM
Re: last login script help
for i in `cat monthfile`
do
<script> | grep ${i} >> ${i}
done
for i in `cat monthfile`
do
sort -k 5n,5 ${i} > ${i}x
done
for i in `cat monthfile`
do
cat ${i}x >> lastlogin
rm ${i} ${i}x
done
Im sure there are less painful ways of doing this but its a way.
good luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2001 05:24 AM
05-09-2001 05:24 AM
Re: last login script help
Like I said there are less painful ways of doing what you want, James does what you want, and you can cut out what you dont, that it reports.
James,
Pretty cool script, Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2001 03:39 AM
05-10-2001 03:39 AM
Re: last login script help
Thank you but, it still does not sort in either direction, either oldest to newest or newest to oldest. In fact, if you don't mind me saying so, my script is actually a little cleaner in the output. For example, here is a sample:
root ftp Wed May 2 12:46 - 12:47 (00:01)
cherubin ttyp1 Tue May 8 15:48 - 16:14 (00:26)
admin ttypd Mon Mar 12 15:15 - 15:22 (00:06)
lpiscate ttyp9 Thu Mar 22 10:28 - 12:51 (02:23)
archer ttyp6 Tue May 8 17:07 - 17:52 (00:45)
stephens pty/ttys3 Tue May 8 11:44 - 13:16 (01:32)
barthele ttyq7 Tue May 8 08:36 - 16:48 (08:11)
toigo ttyr6 Tue May 8 08:43 - 17:37 (08:53)
petrecca ttyq2 Tue May 8 13:35 - 15:45 (02:10)
Thanks, I will keep looking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2001 06:29 AM
05-10-2001 06:29 AM
Re: last login script help
If you run the '-v(erbose)' variation of the first script I offered, you would see that the sort order is ascending last login (oldest date and time to most recent date and time) within user as ordered in /etc/passwd.
In any event, if all that you want is one line per user, from most recent date and time of login to the oldest, with an ascending user (account) bias, then try the attached script.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2001 06:46 AM
05-10-2001 06:46 AM
Re: last login script help
Hmm, I am not sure about this now. Where do I put the -v (verbose)?
In the last or in the sort?
Nickd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2001 06:59 AM
05-10-2001 06:59 AM
Re: last login script help
In my first attachment, you could run the script with or without the '-v' option as:
# /tmp/jrf_last
# /tmp/jrf_last -v
Simply run the second script in the second attachment as:
# /tmp/jrf_lastuser
This last script, I believe, is very close to that which you are looking.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2001 09:53 AM
05-10-2001 09:53 AM
Re: last login script help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2001 04:34 AM
05-14-2001 04:34 AM
Re: last login script help
Close, but not yet. Am I missing something?
This is the script that I am using.
Unfortunately, it does not sort by date, which is what I was looking for.
Should I use runacct instead?
Thanks,
#!/usr/bin/sh
#
LOG=/tmp/last.log
IFS=:
#
rm -f $LOG
#
while read USER NULL
do
last -1 $USER | awk 'NF > 6 {print $0}' >> $LOG
done < /etc/passwd
#
sort -o $LOG -Mrk4 -krn5 -krn6.1,6.2 -krn6.4 -kb1 $LOG
#
#.jrf.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2001 04:43 AM
05-14-2001 04:43 AM
SolutionOK, you have me confused. The script I gave you *does* sort by date. The output is in descending date order (i.e. most recent date, first) with *one* entry (if available) from the /var/adm/wtmp file for every user defined in /etc/passwd.
What do you want?
...JRF...
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2001 06:46 AM
05-15-2001 06:46 AM
Re: last login script help
You are absolutely right.
The script is perfect for me. I must have been running the wrong version or something.
Thanks and don't mind my pointy headedness.
<:-)
Nickd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2001 06:55 AM
05-15-2001 06:55 AM
Re: last login script help
No problem; I've certainly been there too...just glad to have been of help.
Regards!
...JRF...