Skip to content

Instantly share code, notes, and snippets.

@drpauldixon
Last active November 25, 2016 09:42
Show Gist options
  • Save drpauldixon/be82f3b0092bfdd326861c9aecc492a0 to your computer and use it in GitHub Desktop.
Save drpauldixon/be82f3b0092bfdd326861c9aecc492a0 to your computer and use it in GitHub Desktop.
#!/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