33 lines
914 B
Bash
33 lines
914 B
Bash
|
#!/bin/bash
|
||
|
PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
|
||
|
|
||
|
#Use ./logger.sh <logfile>
|
||
|
|
||
|
# Log parameters
|
||
|
REMOTE_SERVER="estudiset.backups"
|
||
|
REMOTE_PATH="/var/www/html/logs/clamav/"
|
||
|
PUBLIC_LOG_URL="https://logs.studi7.com/clamav/"
|
||
|
LOG_PRESERVE_DAYS=30
|
||
|
|
||
|
# create remote folder to store logs if not exist
|
||
|
ssh $REMOTE_SERVER "mkdir -p $REMOTE_PATH"
|
||
|
|
||
|
# Copy local logfile to remote destination
|
||
|
scp $1 "$REMOTE_SERVER:$REMOTE_PATH"
|
||
|
|
||
|
# Clear x days old remote logs
|
||
|
ssh $REMOTE_SERVER 'bash -s' << EOF
|
||
|
find $REMOTE_PATH -maxdepth 1 -mtime +$LOG_PRESERVE_DAYS -exec "rm" -R {} \;
|
||
|
EOF
|
||
|
|
||
|
# return final log url
|
||
|
# get file name in case of $1 is a path
|
||
|
file=$(basename -- "$1")
|
||
|
extension=${file##*.}
|
||
|
base=$(basename "${file%.*}")
|
||
|
# change to txt if log is another text format
|
||
|
if [ $extension != "txt" ]; then
|
||
|
ssh $REMOTE_SERVER "mv $REMOTE_PATH$file $REMOTE_PATH$base.txt"
|
||
|
fi
|
||
|
echo "${PUBLIC_LOG_URL}${base}.txt"
|