Script to truncate wtmp files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to truncate wtmp files
# 1  
Old 05-23-2014
Script to truncate wtmp files

Hi,

Does anyone have a script to truncate the wtmp file.

I want to move older entries in the wtmp to a new file and move it out of var/adm and shrink the size.
# 2  
Old 05-26-2014
What OS are you on?

Linux uses logrotated to handle this, on AIX you would use fwtmp and if on Solaris you would most likely use logadm.
# 3  
Old 05-27-2014
I am on AIX.
How to use fwtmp to rotate the logs?
# 4  
Old 05-27-2014
Here you keep the last 500 and compress the rest and store in /scratch.

Code:
KEEP=500
DEST=/scratch

# Delete all but last $KEEP lines from wtmp
/usr/lib/acct/fwtmp < /var/adm/wtmp > $DEST/wtmp.out
tail -$KEEP $DEST/wtmp.out | /usr/lib/acct/fwtmp -ci > /var/adm/wtmp

# Keep everything except last $KEEP line in $DEST bzip2 date-stamped file
sed -e :a -e '$d;N;2,'$KEEP'ba' -e 'P;D'  $DEST/wtmp.out | bzip2> $DEST/wtmp_$(date +%Y%m%d).bz2
rm $DEST/wtmp.out

Note: if you don't have bzip2 installed, you could use compress instead
# 5  
Old 05-28-2014
Thank you for the script.
let me test in one of my server.

---------- Post updated at 09:36 AM ---------- Previous update was at 08:51 AM ----------

It worked. Perfect script.
Thank you very much Chuber XL.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Red Hat

wtmp output

Hi, Can anybody explain wtmp output fields? A dir was created at 7:11pm and I wanted to find out who was logged in at that time but as you can see there is no ip address listed when I run utmpdump against the wtmp file..... R, D. (1 Reply)
Discussion started by: Duffs22
1 Replies

2. Shell Programming and Scripting

Making wtmp files readable one at a time

New Unix user/scripter here. Been trying to solve a problem for two days now with no luck. Hoping someone here has an answer. Essentially I have a list of wtmp files which I have decompressed and copied to a temporary directory. Using the following command I can turn them into a file than can... (4 Replies)
Discussion started by: Stryfe16
4 Replies

3. UNIX for Dummies Questions & Answers

Script required to truncate all the lines except a specific snippet.

Hi, I have a file with the following structure. XXXXX........... YYYYY........... ................. .................. ZZZZZZ...... qwerty_start.............. .................. ................. .................. querty_end................ .............................. (3 Replies)
Discussion started by: abinash
3 Replies

4. Shell Programming and Scripting

Truncate Log files

Hi Gurus, I have several log files running in real time and needs to be truncated 50% or all but has to keep the logs piling up. Any ideas? For example: /var/adm/messages and others apps log files Thanks in advance! (7 Replies)
Discussion started by: anonymous1
7 Replies

5. Shell Programming and Scripting

truncate file script is not working

Hi All, I have an application which writes log in to a file. The file size becomes around min of 800 MB a day. So I have written a script which backup the file and truncate the original file. My script is like this cp X.log /backup/X.log1 > X.log But the second truncate command... (3 Replies)
Discussion started by: mvenkat_in
3 Replies

6. UNIX for Dummies Questions & Answers

truncate wtmp

I have AIX5.1 I have been trying to learn how to truncate the /var/adm/wtmp file. I have seen several things on google actually but don't quite understand. I also searched your forums but couldn't find it. one says this ">/var/adm/wtmp Is that all I do? I have a seperate question also. I was... (1 Reply)
Discussion started by: rocker40
1 Replies

7. UNIX for Dummies Questions & Answers

wtmp

Hi, is it ok if i delete wtmp on HPUX 11 under /var/adm It is filling up that filesystem Cheers (2 Replies)
Discussion started by: dsharples
2 Replies

8. UNIX for Dummies Questions & Answers

Resetting WTMP?

When I type last oracle I get dates from Nov 28, 2000 all the way back to the beginning of time it seems. The 11-28-2000 entry states that Oracle is still logged in, but if you type a who, it shows only 1 entry - the currently logged in user (Me as oracle), but I logged in only minutes ago - and... (4 Replies)
Discussion started by: cuppjr
4 Replies

9. UNIX for Dummies Questions & Answers

Need Wtmp Reader

I would loke to read the WTMP file. This is a binary file in the /var/logs directory. Is there any utility which will convert this binary file to ASCII format? (1 Reply)
Discussion started by: pgold1
1 Replies
Login or Register to Ask a Question