Last active
November 25, 2016 09:42
-
-
Save drpauldixon/be82f3b0092bfdd326861c9aecc492a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Collect netstat statistics. Run via jenkins or cron. | |
TIMESTAMP=$(date +%a.%b.%d.%Y_%Hh.%Mm.%Ss) | |
DAY=$(date +%A) | |
LOGDIR=~/netstat_logs | |
# Create log directory if not alreay there | |
if [ ! -d $LOGDIR ] | |
then | |
mkdir $LOGDIR | |
fi | |
cd $LOGDIR | |
# Create day directory if not already there | |
if [ ! -d $DAY ] | |
then | |
mkdir $DAY | |
fi | |
# Remove logs older than 14 days | |
find . -type f -mtime +14 -exec rm -f {} \; | |
# Dump netstat results to log file | |
cd $DAY | |
echo $TIMESTAMP > $TIMESTAMP.log | |
netstat -tneoCT >> $TIMESTAMP.log 2>&1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment