Skip to content

Instantly share code, notes, and snippets.

@tuxfight3r
Created February 18, 2015 21:24
Show Gist options
  • Save tuxfight3r/0f11e936b4cfe1e7e45b to your computer and use it in GitHub Desktop.
Save tuxfight3r/0f11e936b4cfe1e7e45b to your computer and use it in GitHub Desktop.
proftpd xferlog logsplit script
[root@server02 scripts]# cat rmp-logsplit.sh
#!/bin/bash
#Date:08/01/2015
#Purpose:Provide Everyday the previous day Transfer logs for RMP as logrotate runs weekly
#Daily logs are available under location /sftp/home/rmp_inbound/Logs/sftp-xfer-201x-xx-xx.log
#place the log under /opt/scripts/ and run under cron for logs
#Author: Mohan
#Yesterdays date for logfile as cron is run the following day
#Output: "2014-01-08"
FULLDATE=$(date +%d-%m-%Y -d yesterday)
#Output: "Jan 08"
MONTHDAY=$(date +'%b %d' -d yesterday)
#Output: "Mon"
TODAY=$(date +%a)
#Output: "20140104"
PRV_SUNDAY=$(date +%Y%m%d -d '8 days ago')
LOG_FOL="/var/log/proftpd"
SRC_FILE="sftp-xferlog"
DST_FOLDER="/sftp/home/rmp_inbound/Logs"
OUT_FILE="${DST_FOLDER}/sftp-xferlog-${FULLDATE}.log"
#simple logic to grep logs from rotated files
if [ ${TODAY} == "Mon" ]; then
#zgrep the previous sunday rotated logfile to capture the first 3 hours log if exists
if [ -s ${LOG_FOL}/${SRC_FILE}-${PRV_SUNDAY}.gz ]; then
zgrep "${MONTHDAY}" ${LOG_FOL}/${SRC_FILE}-${PRV_SUNDAY}.gz \
| egrep "rmp_intuser|rmp_extuser" >> ${OUT_FILE}
fi
#grep the current file for the day
grep "${MONTHDAY}" ${LOG_FOL}/${SRC_FILE} \
| egrep "rmp_intuser|rmp_extuser" >> ${OUT_FILE}
else
#grep the current file for the day
grep "${MONTHDAY}" ${LOG_FOL}/${SRC_FILE} \
| egrep "rmp_intuser|rmp_extuser" >> ${OUT_FILE}
fi
#Change the new file permissions
chmod 660 ${OUT_FILE}
chown proftpd.ftpgroup ${OUT_FILE}
#Delete if the file is empty
if ! [ -s ${OUT_FILE} ]; then
:
# rm -fv ${OUT_FILE}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment