Skip to content

Instantly share code, notes, and snippets.

@ksaver
Created May 15, 2019 03:01
Show Gist options
  • Select an option

  • Save ksaver/54c2dd46895caf2b570ea3fe7b96dc1f to your computer and use it in GitHub Desktop.

Select an option

Save ksaver/54c2dd46895caf2b570ea3fe7b96dc1f to your computer and use it in GitHub Desktop.
trim pcap files for the previous day
#!/bin/bash
#
# trim-yesterday-pcaps.sh
# trim pcap files for the previous day
# ksaver, May 2019
SENSOR_NAME=$(hostname)
IFACE=eth1
PCAP_SIZE=102400
YESTERDAY=$(date -d "$date - 1 days" +"%Y-%m-%d")
DAILYLOGS="/nsm/sensor_data/$SENSOR_NAME-$IFACE/dailylogs/$YESTERDAY"
SCRIPTNAME=$(basename $0 .sh)
LOGFILE=/var/log/$SCRIPTNAME.log
PRESIZE=$(du -h $DAILYLOGS | awk '{print $1}')
function timestamp() {
date +"%Y-%m-%d %H:%M:%S"
}
function main() {
echo "$(timestamp): Trimming $YESTERDAY pcaps.. [PID: $$]"
echo "$(timestamp): Pcaps size previous to trim: $PRESIZE"
echo -n $(timestamp)
/usr/local/bin/trimpcap.py $PCAP_SIZE $DAILYLOGS/*
if [ $? -eq 0 ]; then
POSTSIZE=$(du -h $DAILYLOGS | awk '{print $1}')
echo "$(timestamp): Successful pcap trimming"
echo "$(timestamp): $YESTERDAY directory size: $POSTSIZE"
else
echo "$(timestamp): Error occurred while trimming!"
fi
}
main >> $LOGFILE
@ksaver
Copy link
Author

ksaver commented May 15, 2019

Add this to a cron task and you're all set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment