AIX – Unix – Script to Clean/Shrink WTMP file size

Today I came across an AIX wtmp file that was 1.9 GB in size. Needed to shrink the file down to keep at least the last 300 lines. Once I was completed, the file was less than 1 MB. I wrote the below script to clean the wtmp file, you are able to choose where to create the temp file, and how many lines you want to keep as well.

### Clean the wtmp file online ###
bold=`tput bold`
normal=`tput sgr0`
df -gv
ls -al /var/adm | awk '{ print $1, $2, $3, $4, (($5/1048576))"\t", $6, $7, $8, $9 }'
echo "${bold}Where do you want to create a temp wtmp file. Example /tmp - DO NOT use a trailing / in path.:${normal}"
read TWTMP
echo "your input was $TWTMP"
echo "${bold}How many lines would you like to shrink the file to. Example 300.:${normal}"
read LINES
#if [ -s /var/adm/wtmp ]
/usr/sbin/acct/fwtmp < /var/adm/wtmp > $TWTMP/temp.wtmp
/usr/bin/tail -$LINES $TWTMP/temp.wtmp | /usr/sbin/acct/fwtmp -ic > /var/adm/wtmp
/usr/bin/rm $TWTMP/temp.wtmp

, ,

Comments are closed.