Created
May 15, 2019 03:01
-
-
Save ksaver/54c2dd46895caf2b570ea3fe7b96dc1f to your computer and use it in GitHub Desktop.
trim pcap files for the previous day
This file contains hidden or 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 | |
| # | |
| # 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this to a cron task and you're all set.