- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- trim wtmp file by date
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
07-02-2004 03:10 AM
07-02-2004 03:10 AM
So I first plan to execute "/usr/sbin/acct/fwtmp < /var/adm/wtmp"
to get an ascii version of the file. But the problem I have is that I don't see any easy way to use awk to extract the month and year since the number of fields in the output file can be different.
For example, my output can be:
xxx2923 ta pts/ta 10765 8 0000 0000 1018961181 Apr 16 07:46:21 2002
xxx2923 ts/2 pts/2 17737 7 0000 0000 1018974794 Apr 16 11:33:14 2002 10.0.42.171 10.0.42.171
ts/1 pts/1 8025 8 0000 0000 1018992157 Apr 16 16:22:37 2002
ts/0 pts/0 7717 8 0000 0000 1018992248 Apr 16 16:24:08 2002
ts/2 pts/2 17737 8 0000 0000 1018992250 Apr 16 16:24:10 2002
root remshd 19308 7 0000 0000 1019039404 Apr 17 05:30:04 2002 10.0.48.192 pvdv1d09
(note: lines 3,4,5 are blank in the first field)
I can't just use awk to print field $9 to get the month, since field 9 changes depending on the data.
The month and year are always in the same column positions; is there some way to extract a field based on its position in the record (awk or something else)?
TIA,
Scott
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2004 03:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2004 03:16 AM
07-02-2004 03:16 AM
Re: trim wtmp file by date
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2004 03:17 AM
07-02-2004 03:17 AM
Re: trim wtmp file by date
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2004 03:28 AM
07-02-2004 03:28 AM
Re: trim wtmp file by date
When you want to excecute it do
Current_month=`date "+%b"`
count=`grep "$Current_month" /tmp/temp.txt"|awk -F = '{print $1}'`
count3=`grep $(($count-3)) /tmp/temp.txt|awk -F = '{print $1}'`
count2=`grep $(($count-2)) /tmp/temp.txt|awk -F = '{print $1}'`
count1=`grep $(($count-1)) /tmp/temp.txt|awk -F = '{print $1}'`
fwtmp < /var/adm/wtmp > /tmp/wtmp.txt
egrep "$count3|$count2|$count1" /tmp/wtmp.txt |fwtmp -ic > /var/adm/wtmp
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2004 03:53 AM
07-02-2004 03:53 AM
Re: trim wtmp file by date
/usr/sbin/acct/fwtmp < /var/adm/wtmp | \
while read RECORD ; do
_month=`print "$RECORD" | cut -c58-60`
_year=`print "$RECORD" | cut -c74-77`
done
but this only works when the first field is not blank.. Any ideas?