Tuesday, November 10, 2015

Short Script Version Whatever

Yet another quick and dirty script I don't want to have to rewrite, but is only useful to me.

#!/bin/bash

#Automates the renaming and "parsing" of the failed logon report from redacted
#Assumes being run in the same folder as the report, and that the report is named LOCKEDCONSOLE.XLS

#Store IFS
OLDIFS=$IFS

#Set new IFS
IFS=$'\n'

#Check to see if there is a new file, and rename it if there is.
if [ -e ./LOCKEDCONSOLE.XLS ]
then
    mv LOCKEDCONSOLE.XLS lc-$(date "--date=${dataset_date} - ${date_diff} 1 day" +%m-%d-%y).xls
fi

#Clean up old files (keeps two weeks worth)
for line in $(ls -lha | grep -v "dr\|script\|total")
do
    if (( $(date -d "$(echo $line | awk {'print $6,$7'})" +%s) < $(date "--date=${dataset_date} - ${date_diff} 14 day" +%s) ))
    then
        rm $(echo $line | awk {'print $9'})
    fi
done

#Get a count of failed logins by user ID.
cat *.xls | awk {'print $2'} | sort | uniq -c | sort -n | tail -n 30

#Restore IFS
IFS=$OLDIFS

No comments:

Post a Comment