Simple Log Archiving Script

Made this script for a Linux lab. Thought it might be a useful reference for someone.

#!/bin/bash

#Looks for the string "1 521 1" and copes it to audit.chk
 cat audit.log | grep "1 521 1" > audit.chk

#Wordcounts audit.log and audit.chk and saves them to variables for later use
 CHKWC=`cat audit.chk | wc -l`
 LOGWC=`cat audit.log | wc -l`

#If the audit.log file is bigger than 2000 lines it moves the
 #moves the first 2000 lines to archive.date
 if [ "$LOGWC" -gt "2000" ]
 then
 DATE=`date '+%m%d%y'`
 head -n 2000 audit.log > audit.$DATE
 sed -i '1,2000d' audit.log
 fi

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s